2个回答
展开全部
代码如下:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class App {
public static void main(String[] args) throws FileNotFoundException, IOException {
try (
FileInputStream inputStream = new FileInputStream(new File("d:\\temp\\abc.txt"));
InputStreamReader streamReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(streamReader);
FileOutputStream outputStream = new FileOutputStream(new File("d:\\temp\\output.txt"));
OutputStreamWriter streamWriter = new OutputStreamWriter(outputStream);
BufferedWriter writer = new BufferedWriter(streamWriter);
) {
int count = 1;
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(count++ + ": " + line);
writer.newLine();
}
}
System.out.println("done.");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询