I'm doing a little application where I'm moving around some circles, squares and triangles. Which coordinates I read from a txt file. But once I'm done moving them I'd like to save their coordinates in the same txt file.
This is how the code looks like right now:
import java.io.FileNotFoundException;
import se.lth.cs.ptdc.window.SimpleWindow;
public class ShapeTest {
public static void main(String[] args) throws FileNotFoundException {
SimpleWindow w = new SimpleWindow(600, 600, "ShapeTest");
ShapeList shapes = new ShapeList();
java.util.Scanner scan = null;
try {
scan = new java.util.Scanner(new java.io.File("shapedata.txt"));
} catch (java.io.FileNotFoundException e) {
System.err.println("shapedata.txt couldn't be found");
}
int x,y,z;
while(scan.hasNext()) {
String s = scan.next();
if (s.contentEquals("S")){
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
shapes.insert(new Square(x,y,z));
} else if (s.contentEquals("C")) {
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
shapes.insert(new Circle(x,y,z));
} else if (s.contentEquals("T")) {
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
shapes.insert(new Triangle(x,y,z));
}
}
shapes.draw(w);
CommandDispatcher cd = new CommandDispatcher(w,shapes);
cd.mainLoop();
}
}
What would I need to add? I tried FileUtils.writeStringToFile
without any good result.