大家好
我正在获取鼠标点击的坐标并想将其保存在文本文件中。
有了这段代码,
public void mouseClicked(MouseEvent event) {
PrintWriter outputStream = null;
try{
outputStream =new PrintWriter( new FileOutputStream("stuff.txt"));
}
catch (FileNotFoundException e){
System.out.println("Error opening the file stuff.txt.");
System.exit(0);
}
details = String.format("%s, %s", event.getX(), event.getY());
outputStream.printf("%s, %s\n", event.getX(), event.getY());
statusBar.setText(details);
outputStream.close();
}
我只得到第一次点击的坐标。
你能告诉我如何连续记录我点击的所有坐标吗?
谢谢:)
最佳答案
在append mode中打开FileOutputStream
:
outputStream = new PrintWriter(new FileOutputStream("stuff.txt", true));
关于java - 不断向文件中写入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18571657/