在Linux下读写文件和windows差不多,区别就在于路径上:
new File("/home/用户名/文件名")即可
如果不知道路径名,可以在命令行输入pwd进行查看BufferedWriter bw = null;
try {
File file = new File("/home/qiulei/points.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
bw = new BufferedWriter(fw);
for(Point2D p : this.allpoint)
{
String s = String.valueOf(p.getX());
bw.write(s);
bw.write(' ');
s = String.valueOf(p.getY());
bw.write(s);
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}