Questions tagged [fileinputstream]

FileInputStream is a Java class meant for reading streams of raw bytes.

A FileInputStream is a Java class for reading the contents of a file from a stream. When you perform a read() on the stream, the appropriate data is read from the file and returned to the application.

1141 questions
15
votes
5 answers

how to write content in a Specific position in a File

Suppose I have a file named abhishek.txt and that contains the following line I am , and what is your name. Now I want to write Abhishek after "I am" like I am Abhishek, .. How to write the content in this specific position directly.
Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128
15
votes
1 answer

How to create a ZIP InputStream in Android without creating a ZIP file first?

I use NanoHTTPD as web server in my Android APP, I hope to compress some files and create a InputStream in server side, and I download the InputStream in client side using Code A. I have read Code B at How to zip and unzip the files?, but how to…
HelloCW
  • 843
  • 22
  • 125
  • 310
14
votes
5 answers

ObjectInputStream happy with FileInputStream, not happy with getResourceAsStream

I have some pretty standard code which takes in a serialized object from a stream, which bascially looks like this: Object getObjectFromStream(InputStream is) { ObjectInputStream ois = new ObjectInputStream(is); return ois.readObject(); …
barryred
  • 1,103
  • 1
  • 17
  • 27
14
votes
5 answers

File not found exception (Path from URI)

I'm trying to get a FileInputStream object for the picture a user selects from their gallery and when I'm trying to open the file from the URI I receive, it keeps saying FileNotFoundException... Here's the code I'm using to fire off the intent for…
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
14
votes
2 answers

How to create a zip file of multiple image files

I am trying to create a zip file of multiple image files. I have succeeded in creating the zip file of all the images but somehow all the images have been hanged to 950 bytes. I don't know whats going wrong here and now I can't open the images were…
Vighanesh Gursale
  • 921
  • 5
  • 15
  • 31
12
votes
3 answers

C++ How to read in objects with a given offset?

Now I have a file with many data in it. And I know the data I need begins at position (long)x and has a given size sizeof(y) How can I get this data?
shevron
  • 282
  • 2
  • 4
  • 14
10
votes
4 answers

Read/write file to internal private storage

I'm porting the application from Symbian/iPhone to Android, part of which is saving some data into file. I used the FileOutputStream to save the file into private folder /data/data/package_name/files: FileOutputStream fos = iContext.openFileOutput(…
STeN
  • 6,262
  • 22
  • 80
  • 125
10
votes
1 answer

How can closing a FileInputStream cause a "No Space Left on Device" error?

I am a bit confused with an error my program started throwing recently. java.io.IOException: No space left on device at java.io.FileInputStream.close0(Native Method) at java.io.FileInputStream.close(FileInputStream.java:259) at…
Judicator
  • 133
  • 1
  • 8
10
votes
5 answers

Why does the read() in FileInputStream return an integer?

This page shows says that it is so that the method can return -1 when it wants to indicate that there are no more bytes to be read. But a byte ranges from -128 to 127, right? And wouldn't it make more sense for the return type of read() to be byte…
GrowinMan
  • 4,891
  • 12
  • 41
  • 58
9
votes
6 answers

What is wrong with FileInputStream.read(byte[])?

In response to my answer to a file-reading question, a commenter stated that FileInputStream.read(byte[]) is "not guaranteed to fill the buffer." File file = /* ... */ long len = file.length(); byte[] buffer = new byte[(int)len]; FileInputStream…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
9
votes
0 answers

Java FileOutputStream when will written bytes be ready for read?

Assuming I have 2 threads, one is writing to a FileOutputStream and one is reading from a FileInputStream. The first thread has written x bytes. When are the bytes considered as ready for reads? The flush() method has an empty implementation on…
galusben
  • 5,948
  • 6
  • 33
  • 52
9
votes
2 answers

Getting the list of filenames from resource folder when running in jar

I have some Json files in the folder "resource/json/templates". I want to read these Json files. So far, the snippet of code below is allowing me to do so when running the program in IDE but it fails when I run it in the jar. JSONParser parser =…
Juvenik
  • 900
  • 1
  • 8
  • 26
9
votes
2 answers

How do i read in binary data files in java

So I'm doing a project for school where I need to read in a binary data file and use it to make stats, like strength and wisdom, for characters. It's set up so the first 8 bits make up one stat. I was wondering what the actual syntax to do this is.…
Ionterac
  • 91
  • 1
  • 1
  • 4
9
votes
16 answers

Read data from a text file using Java

I need to read a text file line by line using Java. I use available() method of FileInputStream to check and loop over the file. But while reading, the loop terminates after the line before the last one. i.e., if the file has 10 lines, the loop…
Saran
  • 213
  • 2
  • 5
  • 13
9
votes
2 answers

How to get a File instance of a drawable?

Below is the code that I cope with logo printing. The logo is placed in res/drawable folder. When I run the app, it throws: java.io.FileNotFoundException: /android.resource:/com.android.test/2130837505 (No such file or directory). Any advice? …
user1437534
  • 129
  • 3
  • 8
1
2
3
76 77