例如,如何读取 20 行readFile或 n 行并将其保存到另一个文件(writeFile)?
public class Test_read_file {
public static List<String> readFile() throws IOException {
try(BufferedReader br = new BufferedReader(new FileReader("C:\\\\\\\\Users\\\\\\\\Admin\\\\\\\\Desktop\\\\\\\\Work Files\\\\\\\\314-WO0000001133814\\\\\\\\Cards\\\\\\\\MBD10760_182.out"))){
List<String> listOfData = new ArrayList<>();
String d;
while((d = br.readLine()) != null){
listOfData.add(d);
}
return listOfData;
}
}
public static void writeFile(List<String> listOfData) throws IOException{
try(BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\\\\\\\Users\\\\\\\\Admin\\\\\\\\Desktop\\\\\\\\Work Files\\\\\\\\314-WO0000001133814\\\\\\\\Cards\\\\\\\\MBD10760_187.out"))){
for(String str: listOfData){
bw.write(str);
bw.newLine();
}
}
}
public static void main(String[] args) throws IOException {
List<String> data = readFile();
writeFile(data);
}
}
梵蒂冈之花
长风秋雁
叮当猫咪
相关分类