编写一个Java应用程序,使用Java的输入输出流技术将FileInput.txt的内容逐行读出,每读出一行就顺序为其
1个回答
展开全部
import java.io.*;
public class FileLineNumber {
public static void main(String[] args) throws Exception {
appendLineNumber(new File("FileLineNumber.java"), new File("a.txt"));
}
public static void appendLineNumber(File from, File to) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(from));
StringBuilder sb = new StringBuilder();
String t;
int lineNumber = 1;
while((t = in.readLine()) != null) {
sb.append(lineNumber + " ");
sb.append(t);
sb.append(System.getProperty("line.separator"));
lineNumber++;
}
in.close();
BufferedWriter out = new BufferedWriter(new FileWriter(to));
out.write(sb.toString());
out.close();
}
}
请采纳答案,支持我一下。
public class FileLineNumber {
public static void main(String[] args) throws Exception {
appendLineNumber(new File("FileLineNumber.java"), new File("a.txt"));
}
public static void appendLineNumber(File from, File to) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(from));
StringBuilder sb = new StringBuilder();
String t;
int lineNumber = 1;
while((t = in.readLine()) != null) {
sb.append(lineNumber + " ");
sb.append(t);
sb.append(System.getProperty("line.separator"));
lineNumber++;
}
in.close();
BufferedWriter out = new BufferedWriter(new FileWriter(to));
out.write(sb.toString());
out.close();
}
}
请采纳答案,支持我一下。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询