我的目标是加载 save.txt 文件中的内容。我该怎么写呢?我不确定我的写入代码是否正在写入 save.txt。可以看一下吗?
else if (savePicture.isPointInElement(clickX, clickY)){
FileWriter fw = new FileWriter("save.txt");
for (int i = 0; i < arraysticker.length; i++){
if (arraysticker[image]!=null){
String name;
int x,y;
name = sticker.getname();
x = sticker.getx();
y = sticker.gety();
fw.write(name + " " + x + " " + y + "\n");
}
}
}
这是我添加的“贴纸”代码之一。
if (hatSoundPlay){ //if hatSoundPlay is true
hatsound.play(); //and a hatsound will play
sticker sticker1 = new sticker();//creates a new sticker1
sticker1.arraysticker(hatPicture, "hat.png", clickX, clickY);//places sticker
image ++;//increments image by 1
arraysticker[image] = sticker1;//puts sticker 4 into the array
sticker11 = true;
最佳答案
FileWriter fw = new FileWriter("save.txt");
for (int i = 0; i < arraysticker.length; i++){
if (arraysticker[image]!=null){
String name;
int x,y;
name = sticker.getname();
x = sticker.getx();
y = sticker.gety();
fw.write(name + " " + x + " " + y + "\n");
}
}
**fw.flush();
fw.close();**
关于java - 如何编写扫描仪代码来加载先前保存在 save.txt 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205190/