【发布时间】:2013-06-10 02:45:37
【问题描述】:
我有以下任务要完成:
编写了一个程序,该程序读取一个文件并将该文件的副本写入另一个插入行号的文件。
到目前为止,我编写了下面发布的代码。此代码读取文本并将其复制到另一个文件,但我无法弄清楚如何对新文本文件中的每一行进行编号。有人可以告诉我怎么做吗?
import java.io.*;
class FileCopy
{
public static void main(String[] args)
{
try
{
File fileIn = new File("Assign4.txt");
File fileOut = new File("target.txt");
FileInputStream streamIn = new FileInputStream(fileIn);
FileOutputStream streamOut = new FileOutputStream(fileOut);
int c;
while ((c = streamIn.read()) != -1)
{
streamOut.write(c);
}
streamIn.close();
streamOut.close();
}
catch (FileNotFoundException e)
{
System.err.println("FileCopy: " + e);
}
catch (IOException e)
{
System.err.println("FileCopy: " + e);
}
}
}
谢谢你,感谢你的帮助。
【问题讨论】:
标签: java io numbers try-catch copy-paste