-
- public class 练习
- {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException
- {
- Demo1();
- }
- private static void Demo1() throws FileNotFoundException, IOException {
- BufferedReader br =
- new BufferedReader(new FileReader("day22笔记.txt"));
-
- List<String> l = new ArrayList<>();
- String str ;
- while ((str = br.readLine())!= null)
- {
- l.add(str);
- }
- BufferedWriter bw =
- new BufferedWriter(new FileWriter("反转文件.txt"));
- for(int x = l.size(); x >= 0 ; x--)
- {
- bw.write(l.get(x));
- bw.newLine();
-
- }
- br.close();
- bw.close();
- }
- }
复制代码 我做的练习 要把一个文件里的内容反转一下拷贝到另一个文件里 为什么报错了啊?- Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 28, Size: 28
- at java.util.ArrayList.rangeCheck(ArrayList.java:604)
- at java.util.ArrayList.get(ArrayList.java:382)
- at 日常学习.练习.Demo1(练习.java:75)
- at 日常学习.练习.main(练习.java:24)
复制代码 这个是什么意思啊?
|