我正在创建一个程序,它将打印一个位置的坐标。当它打印到文件中时,它看起来像这样:
Car id distance #spots
java.awt.Point[x=1,y=1]
java.awt.Point[x=2,y=0]
java.awt.Point[x=1,y=0]
car0 java.awt.Point[x=0,y=0] java.awt.Point[x=1,y=0] 1
car1 java.awt.Point[x=2,y=0] java.awt.Point[x=2,y=0] 2
我试图摆脱 java.awt.Point 的出现,所以它只显示坐标。
这是我的代码: public void saveGrid(File name) throws FileNotFoundException {
ArrayList<Car> cars = getCars();
ArrayList<ParkingSpot> spots = getSpots();
PrintWriter fileWriter;
try {
fileWriter = new PrintWriter(name);
fileWriter.println("hi");
fileWriter.println("\n\nCar id distance #spots\n");
fileWriter.println(getPartyLocation());
for(ParkingSpot spot: spots){
fileWriter.println(spot.getLocation());
fileWriter.println("");
}
for (Car car: cars) {
fileWriter.println(car.getId() + " " + car.getStart() + " " + car.getLocation() + " " + car.getNumSpotsTried());
fileWriter.println("");
}
fileWriter.close();
} catch (FileNotFoundException e) {
System.err.println("FileWriting error:" + e);
e.printStackTrace();
}