我来自 C++ 背景,所以请善待我的 n00bish 查询...
我想从输入文件中读取数据并将其存储在字符串流中。我可以使用字符串流在 C++ 中以一种简单的方式完成此操作。我有点迷失在Java中做同样的事情。
以下是我开发的粗略代码/方式,我将逐行读取的数据存储在字符串数组中。我需要使用字符串流将我的数据捕获到(而不是使用字符串数组)中。有什么帮助吗?
char dataCharArray[] = new char[2];
int marker=0;
String inputLine;
String temp_to_write_data[] = new String[100];
// Now, read from output_x into stringstream
FileInputStream fstream = new FileInputStream("output_" + dataCharArray[0]);
// 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;
marker++;
}
编辑:
我想我真正想要的是一个 StringBuffer。我需要从文件中读取数据(可能是到 StringBuffer 中)并将所有数据写入/传输回另一个文件。