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

java read / write construction

Can someone explain me why this construction wont work: while (fileInputStream.available()>0) { fileOutputStream.write(fileInputStream.read()); } and this one works just fine: while (fileInputStream.available()>0) { int data =…
Hikaru
  • 111
  • 8
6
votes
3 answers

How do I convert an InputStream to S3ObjectInputStream in Java?

I want to convert a FileInputStream to a S3ObjectInputStream. This is my current code: InputStream is = new FileInputStream(file); S3ObjectInputStream sObject = (S3ObjectInputStream)is; However, it's giving the error: java.io.FileInputStream cannot…
6
votes
2 answers

reading log file in java

Is it possible to read log files (abc.log) using java? I want a specific string from my log file. suppose this is the content of my logfile. I want the time stamp only (eg: 05:08:37) and print it the console. 2012-12-16 05:08:37,905 [Thread-1] INFO…
smya.dsh
  • 651
  • 5
  • 10
  • 23
6
votes
5 answers

FileInputStream("hello.txt"), doesn't work unless I specify an absolute path (C:\User\Documents etc)

Hi is there any way I can get FileInputStream to read hello.txt in the same directory without specifying a path? package hello/ helloreader.java hello.txt My error message: Error: .\hello.txt (The system cannot find the file specified)
meiryo
  • 11,157
  • 14
  • 47
  • 52
6
votes
3 answers

How can a FileInputStream get the content of File?

I have a file f and I need to affect it into a FileInputStream fs : File f = new File("C:/dir/foo.txt"); FileInputStream fs = (FileInputStream)f; But i get this error : Cannot cast from File to FileInputStream How can fs get the content of f?
user1459961
6
votes
3 answers

Reading file chunk by chunk

I want to read a file piece by piece. The file is split up into several pieces which are stored on different types of media. What I currently do is call each seperate piece of the file and then merge it back to the original file. The issue is that I…
david
  • 244
  • 2
  • 4
  • 11
6
votes
3 answers

JAVA: FileInputStream and FileOutputStream

I have this strange thing with input and output streams, whitch I just can't understand. I use inputstream to read properties file from resources like this: Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream(…
gedO
  • 548
  • 2
  • 7
  • 24
5
votes
2 answers

Error in a middle of writing to outputstream handling

I'm building an httpserver as part of my academic java course, The server should only support basic GET and POST requests. I was wondering if there's an elegant way to handle an error which occures in the middle of writing an html file stream…
Mikey S.
  • 3,301
  • 6
  • 36
  • 55
5
votes
2 answers

Read and copy file with Coroutines

I created the following application to illustrate some doubts. My Example on the Github In this example, I copy a file to another package. My doubts are as follows: Performing the tasks in parallel, is it possible to return the values that were…
5
votes
6 answers

java code to download a file from server

using java code in windows i need to download several files from a directory placed in a server. those files in server are generated separately. so i'll not know the name of those files. is there any way to download it using JAVA and saving it in a…
su03
  • 225
  • 2
  • 6
  • 13
5
votes
3 answers

What's the difference between BufferedInputStream and java.nio.Buffer?

We can get a BufferedInputStream by decorating an FileInputStream. And Channel got from FileInputStream.getChannel can also read content into a Buffer. So, What's the difference between BufferedInputStream and java.nio.Buffer? i.e., when should I…
expoter
  • 1,622
  • 17
  • 34
5
votes
2 answers

Skip() method in IO java?

I know that skip(long) method of FileInputStream skips bytes from the starting position of the file and places the file pointer. But If we want to skip only 20 characters in the middle of the file, and the remaining part of the file as to be read,…
Quan Nguyen
  • 698
  • 1
  • 9
  • 19
5
votes
1 answer

FileChannel returns wrong file size of file in assets folder

I am trying to read a File from the raw folder in my assets using a FileInputStream. This is how I create the FileInputStream: AssetManager assetManager = getAssets(); AssetFileDescriptor fileDescriptor =…
Mike Herasimov
  • 1,319
  • 3
  • 14
  • 31
5
votes
2 answers

Need to convert AssetInputStream to FileInputStream

I have implemented a data structure which is working on my computer and now I am trying to port it into my android application. I open a raw .dat resource and get a InputStream but I need to get a FileInputStream: FileInputStream fip =…
Joop
  • 3,706
  • 34
  • 55
5
votes
1 answer

How does the compiler optimize getline() so effectively?

I know a lot of a compiler's optimizations can be rather esoteric, but my example is so straightforward I'd like to see if I can understand, if anyone has an idea what it could be doing. I have a 500 mb text file. I declare and initialize an…
mock_blatt
  • 955
  • 5
  • 11