I'm coming from a C++ background, so be kind on my n00bish queries...
I'd like to read data from an input file and store it in a stringstream. I can accomplish this in an easy way in C++ using stringstreams. I'm a bit lost trying to do the same in Java.
Following is a crude code/way I've developed where I'm storing the data read line-by-line in a string array. I need to use a string stream to capture my data into (rather than use a string array).. Any help?
char dataCharArray = new char;
String temp_to_write_data = new String;
// Now, read from output_x into stringstream
FileInputStream fstream = new FileInputStream("output_" + dataCharArray);
// Convert our input stream to a BufferedReader
BufferedReader in = new BufferedReader (new InputStreamReader(fstream));
// Continue to read lines while there are still some left to read
while ((inputLine = in.readLine()) != null )
// Print file line to screen
// System.out.println (inputLine);
temp_to_write_data[marker] = inputLine;
I think what I really wanted was a StringBuffer.
I need to read data from a file (into a StringBuffer, probably) and write/transfer all the data back to another file.
What exactly is a string stream? Any reason you can't just read characters from the Reader?
以上就是Capture data read from file into string stream Java的详细内容，更多请关注web前端其它相关文章！