只能写入,课程用缓冲写的,我就想直接用filereader写写,无法读取了,但是可以正常运行
package liu;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class zifuliuwenjian {
public static void main(String[] args) throws IOException {
ArrayList a = new ArrayList();
a.add(“akj");
a.add("shj");
a.add("shbw");
FileWriter w = new FileWriter("D:\\java\\w\\untitled\\zifuliuwenjian.txt");
int index = 0;
for (String r : a) {
w.write(a.get(index));
w.write("\r\n");
char[] ui = a.get(index).toCharArray();
index++;
}
FileReader o = new FileReader("D:\\java\\w\\untitled\\zifuliuwenjian.txt");
char[] kj = new char[1024];
int gh;
while ((gh = o.read(kj)) != -1) {
System.out.println(new String(kj, 0, gh));
}
o.close();
w.close();
}
}