import org.apache.commons.io.IOUtils;
import java.io.*;
public class Hello {
public static void main(String[] args) {
FileOutputStream out = null;
FileInputStream in;
try {
File file=new File("test.txt");
System.out.println(file.getAbsoluteFile());
out=new FileOutputStream("test.txt");
for (int i = 0; i < 10; i++) {
IOUtils.write("test"+"\n",out);
}
in=new FileInputStream("test.txt");
for (Object s:IOUtils.readLines(in)
) {
System.out.println(s);
}
out.close();
in.close();
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
IOUtils 类
FileOutputStream out = null;
FileInputStream in;
读取用:IOUtils.readLines(in)
写入用:IOUtils.write(“test”+"\n",out);