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
184
votes
6 answers

getResourceAsStream() vs FileInputStream

I was trying to load a file in a webapp, and I was getting a FileNotFound exception when I used FileInputStream. However, using the same path, I was able to load the file when I did getResourceAsStream(). What is the difference between the two…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
141
votes
4 answers

Get total size of file in bytes

Possible Duplicate: java get file size efficiently I have a File called filename which is located in E://file.txt. FileInputStream fileinputstream = new FileInputStream(filename); What I want to do is to calculate the size of this file in bytes.…
Illep
  • 16,375
  • 46
  • 171
  • 302
118
votes
5 answers

How to convert FileInputStream to InputStream?

I just want to convert a FileInputStream to an InputStream, how can I do that? e.g FileInputStream fis = new FileInputStream("c://filename"); InputStream is = ?; fis.close();
ranjan
  • 1,739
  • 5
  • 18
  • 22
100
votes
5 answers

What is the difference between Reader and InputStream?

What is the difference between Reader and InputStream? And when to use what? If I can use Reader for reading characters why I will use inputstream, I guess to read objects?
sab
  • 9,767
  • 13
  • 44
  • 51
74
votes
3 answers

Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream?

I was trying to read a file into an array by using FileInputStream, and an ~800KB file took about 3 seconds to read into memory. I then tried the same code except with the FileInputStream wrapped into a BufferedInputStream and it took about 76…
ZimZim
  • 3,291
  • 10
  • 49
  • 67
65
votes
5 answers

Android- how can I convert android.net.Uri object to java.net.URI object?

I am trying to get a FileInputStream object on an image that the user selects from the picture gallery. This is the android URI returned by android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI content://media/external/images/media/3 When I…
lostInTransit
  • 70,519
  • 61
  • 198
  • 274
43
votes
4 answers

Android download PDF from URL then open it with a PDF reader

I am trying to write an app to download PDFs from a URL, store them on SD, then open by Adobe PDF reader or other apps (which ever is able to open the PDF). Until now, I had "successfully downloaded and stored it on SD card" (but every time when I…
sefirosu
  • 2,558
  • 7
  • 44
  • 69
39
votes
6 answers

Usage of BufferedInputStream

Let me preface this post with a single caution. I am a total beginner when it comes to Java. I have been programming PHP on and off for a while, but I was ready to make a desktop application, so I decided to go with Java for various reasons. The…
Jason Watkins
  • 1,705
  • 5
  • 18
  • 30
29
votes
6 answers

How to convert FileInputStream into string in java?

In my java project, I'm passing FileInputStream to a function, I need to convert (typecast FileInputStream to string), How to do it.?? public static void checkfor(FileInputStream fis) { String a=new String; a=fis //how to do convert…
bhushan23
  • 481
  • 1
  • 4
  • 13
29
votes
3 answers

FileInputStream doesn't work with the relative path

I tried to create an object from FileInputStream and pass the relative value of a file to its constructor, but it doesn't work properly and threw a FileNotFoundException try { InputStream is = new FileInputStream("/files/somefile.txt"); } catch…
Mahmoud Elshamy
  • 578
  • 1
  • 5
  • 13
26
votes
9 answers

Java FileInputStream ObjectInputStream reaches end of file EOF

I am trying to read the number of line in a binary file using readObject, but I get IOException EOF. Am I doing this the right way? FileInputStream istream = new FileInputStream(fileName); ObjectInputStream ois = new…
user69514
  • 26,935
  • 59
  • 154
  • 188
23
votes
2 answers

Java fileinputstream using with url

How to input in the fileinputstream, a file to url? I enter the url in the Fileinputstream, but the output of the URL is wrong, because the link slashes are turned backwards like - from / to \ and the double slashes // are \ only one slash and…
weardstuff
  • 781
  • 5
  • 15
  • 22
23
votes
3 answers

How to get files from resources folder. Spring Framework

I'm trying to unmarshal my xml file: public Object convertFromXMLToObject(String xmlfile) throws IOException { FileInputStream is = null; File file = new File(String.valueOf(this.getClass().getResource("xmlToParse/companies.xml"))); try…
Tom Wally
  • 542
  • 3
  • 8
  • 20
21
votes
5 answers

what is the difference in using InputStream instead of FileInputStream while creating the FileInputStream object

This may be a silly one, but I want to know the background operation difference. InputStream is = new FileInputStream(filepath); FileInputStream is = new FileInputStream(filepath); What is the difference between the above two lines of code and in…
Mathan Kumar
  • 634
  • 2
  • 7
  • 19
17
votes
7 answers

Force Delete all files from a folder

I have been using a specific piece of code to delete files from a folder but it is proving very problematic because maybe I forgot to close an InputStream or two. The code I have is so big that I am not be able to see all the Inputstreams that I…
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
1
2 3
76 77