我想从文件中逐个读取字符并将该字符写入另一个文件中,当字符为";“时,我想获取下一行并继续逐个字符读取
我使用FileReader逐个读取字符,使用FileWriter写入字符,问题是我无法获取文件中下一行,程序只处理第一行
有什么想法吗,请
谢谢
发布于 2014-03-26 04:04:59
对于你的问题,我有一个解决方案:
File inputFile = new File("in.txt");
File outputFile = new File("out.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
{
if (c == ';')
out.write('\n');
else
out.write(c);
}
in.close();
out.close(); 如果第一个文件包含:
hello;my;name;is;john第二个文件是:
hello
my
name
is
john这就是你想要的?
如果您有任何问题,欢迎使用:)
https://stackoverflow.com/questions/22644840
复制相似问题