Read from a file using datainputstream




















Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 3 years, 7 months ago.

Active 3 years, 7 months ago. Viewed 4k times. EOFException zel 9. What if the file is of 80GB? Yes, it was, and if it's reading a single line it works correctly. Also, closing is supposed to happen in finally block. And best is to not print some nothing-saying message on exception but just let them go. Since you already have a throws Exception on the method, just remove the entire catch. Only use it when you can handle exceptions in a sensible manner. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. DataInputStream for input text files? Ask Question. Asked 10 years, 11 months ago. Active 9 years ago. Viewed 3k times. Nathaniel Ford Add a comment. I thought NIO due you talked about get some specific part of file.

Since you are using BufferedInputStream, all the data is already being loaded into the memory. Maybe the processing cost to transform that data into String to search on it using REGEX for example would make the solution much simpler and maybe faster. No, no, this discussion is not going in the direction that I wanted it to go. As I wrote earlier, let me make something that works.

I will worry about performance later. Afterall, I am not reading terabytes of data. May be the way I phrased my question was confusing. I will rephrase and report what I have been doing later. Luan Cestari : I admit that I have come to my senses What is happening is that it takes about 50 seconds to search for a predefined keyword. Not acceptable. I have not even begun to read the real stuff-- I need to read large chunk of binary float data "large binary float data here"- from my previous post and that would take some time.

Then there will be files like that. No, no. I can only say that the way I have done is not right. There must be smarter way. What I did: I read the file into a byte array. In the above, we are creating an object for DataInputStream in Java by using its constructor where we can pass our inputStream for which we want to read our data. In the above simple syntax, we are getting an idea of how to use this class to read the primitive type in java int, float, long, double etc.

Simple in the first step, we just create the object and pass our inputStream and using java in build methods to read data like int, float, double and one separate method named as read. This class also contains various methods used to write data to a file.

This has methods specific to int, double, float, etc. We also have methods to read this primitivetype data from a file. It has various method to read data from the input stream to read primitive type object like int, float, double, float, Boolean etc. Methods are mentioned below with example:. DataInputStream; import java.

DataOutputStream; import java.



0コメント

  • 1000 / 1000