- package com.heima.test1;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- public class Test1 {
- /**
- * @throws IOException
- * 将文本反转
- * @throws
- */
- public static void main(String[] args) throws IOException {
- //创建输入流对象
- BufferedReader br = new BufferedReader(new FileReader("aaa.txt"));
- //创建集合
- ArrayList<String> list = new ArrayList<>();
- //将文本内容写入集合中
- String s ;
- while((s = br.readLine())!=null){
- list.add(s);
- }
- br.close();
-
- //创建输出流
- BufferedWriter bw = new BufferedWriter(new FileWriter("bbb.txt"));
- //倒序遍历集合,并写出文本内容
- for (int i = list.size()-1; i >= 0; i--) {
- bw.write(list.get(i));
- bw.newLine();
- }
- bw.close();
- }
- }
复制代码 |
|