fileinputstream

Reading an XML File using FileInputStream (for Java)?

Hi everyone, here's the deal. For my project I have to serialize and deserialize a random tree using Java and XStream. My teacher made the Tree/RandomTree algorithms, so I don't have to worry about that. What I don't know how to do is this: I am using FileInputStream to read/write the xml file that I serialized and deserialized, but ...

Get FileNotFoundException when initialising FileInputStream with File object

I am trying to initialise a FileInputStream object using a File object. I am getting a FileNotFound error on the line fis = new FileInputStream(file); This is strange since I have opened this file through the same method to do regex many times. My method is as follows: private BufferedInputStream fileToBIS(File file){ FileInputSt...

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? ...

Using Java's FileInputStream

In java.io.FileInputStream, there is a method int read(Byte[] buffer,int offset,int numBytes); how we can use this function - is there any difference between this method and read(byte[] buffer)? ...

Java Gridgain application starts to fail after 1 day of stress testing

So I have a an application which is running on top of gridgain and does so quite successfully for about 12-24 hours of stress testing before it starts to act funny. After this period of time the application will suddenly start replying to all queries with the exception java.nio.channels.ClosedByInterruptException (full stack trace is at ...

java FileInputStream - differences based on how the File object is referenced: classloader/filesystem

Hi all, I'm using apache POI to extract some data from an excel file. I need an InputStream to instantiate the POI HSSFWorkbook class HSSFWorkbook wb = new HSSFWorkbook(inputStreamX); I'm finding differences if I try to construct the InputStream object like InputStream inputStream = new FileInputStream(new File("/home/xxx/workspace...

How can I access a txt file in a jar with FileInputStream?

I am aware of the getResourceAsStream() method but there is an issue with the parser that reads the file, the whole structure was implemented to expect a FileInputStream() and the getResourceAsStream() returns an input stream which cannot be casted. Is there any easy "fix" for this situation? ...

Decrypting a file in Java and exporting it to a file without going into infinite loops?

How do you decrypt a file in java and export it to a file without having to end up in an infinite loop if you have more than one user and password. Here is my code and at the end is my test file: import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOE...

How to load a config xml file with FileInputStream, but getting a FileNotFoundException

My build path in Eclipse looks like this: ProjectName -- WEB-INF -- classes -- myClass.class -- configs -- myConfig.xml My absolute path to the config currently looks like this: C:\Development\Java\ProjectName\WEB-INF\configs\myConfig.xml I'm using JAXB for the binding, and it is expecting a FileInpu...

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 methods, and why does one work while the other doesn't? ...

Filling jTable in applet with CSV data. Will compile, will run, no data/table displayed.

I have been attempting to load CSV data into a java applet. I have been able to load the data into a java program but when I make the attempt to recreate this into a java applet, i am having difficulties. Here is the code I have that will run but display nothing: import java.io.*; import java.util.*; import javax.swing.*; import javax...

FileInputStream negative skip

I'm trying to find more about history of java.io.FileInputStream.skip(n) operation when n is negative. According to InputStream documentation: If n is negative, no bytes are skipped. It seems that implementation of FileInputStream from Sun used to throw IOException instead, which is now also documented in Javadoc: If n is negat...

In Java, howd do I iterate through lines in a textfile from back to front

Basically I need to take a text file such as : Fred Bernie Henry and be able to read them from the file in the order of Henry Bernie Fred The actual file I'm reading from is >30MB and it would be a less than perfect solution to read the whole file, split it into an array, reverse the array and then go from there. It ...

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 ObjectInputStream(istream); /** calculate number of items **/ int line_count = 0; while( (String)ois...

FileInputStream throws NullPointerException.

I am getting nullpointerexception, don't know what actually is causing it. I read from java docs that fileinputstream only throws securityexception so don't understand why this exception pops up. here is my code snippet. private Properties prop = new Properties(); private String settings_file_name = "settings.properties"; private String...

Additional spaces in String having read text file to String using FileInputStream

Hi, I'm trying to read in a text file to a String variable. The text file has multiple lines. Having printed the String to test the "read-in" code, there is an additional space between every character. As I am using the String to generate character bigrams, the spaces are making the sample text useless. The code is try{ FileInputSt...

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 10lines, the loop reads only the first 9 lines. Snippet used : while(fis.available() > 0) { char c = (char...

FileReader vs FileInputReader. split vs Pattern

I'm working with a file with about 2G. I want to read the file line by line to find some specific terms. Whitch class can I better use: FileReader or FileInputStream? And how can I find the specific words efficiently. I'm just using the split() method, but may be can I use the java.util.regex.Pattern class in combination with java.util.r...

Usage of BufferedInputStream

Hello everyone. 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 application I am working on is in the beginning stages (less than 5 cla...

servlet: convert an ServletInputStream into a FileInputStream

Hello, i'm writing a servlet that receives a xml file, gives it to another class and gives a html file with some comments back to the client. I'm getting the input-xml with something like: input = request.getInputStream(); but this input is a ServletInputStream and the other class(for the comments) needs a FileInputStream. If i give...