public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("aaa.txt"));
ArrayList<String> list = new ArrayList<>(); //创建集合对象
String line;
while((line = br.readLine()) != null) { //从文本上读取每行数据
list.add(line);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter("aaa.txt"));
for(int i = list.size() - 1; i >= 0; i--) { //倒着遍历集合
bw.write(list.get(i));
bw.newLine();
}
bw.close();
}
|
|