大家好日子,
我正在获取鼠标点击的坐标,并希望将其保存在文本文件中。
使用此代码,
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();
}
我只获得第一次点击的坐标。
您能告诉我如何连续记录我点击的所有坐标吗?
谢谢:)
答案 0 :(得分:5)
打开append mode中的FileOutputStream
:
outputStream = new PrintWriter(new FileOutputStream("stuff.txt", true));