Added file handling
parent
588f7a5263
commit
d640f5a926
|
@ -11,9 +11,12 @@ import java.awt.*;
|
|||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import javax.swing.*;
|
||||
|
||||
public class GamePanel extends JPanel implements Runnable, KeyListener{
|
||||
|
@ -193,4 +196,23 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
return flippedImage;
|
||||
}
|
||||
|
||||
public void writeFile(String fileLocation, String writeString) throws IOException {
|
||||
File newFile = new File(fileLocation);
|
||||
FileWriter fileWriter = new FileWriter(newFile);
|
||||
fileWriter.write(writeString);
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
// will create file if it doesn't exist
|
||||
public String readFile(String fileLocation) throws IOException {
|
||||
File newFile = new File(fileLocation);
|
||||
if (newFile.createNewFile()) {
|
||||
return null;
|
||||
} else {
|
||||
Scanner fileReader = new Scanner(newFile);
|
||||
// using the delimiter \\Z reads the entire file at once
|
||||
return fileReader.useDelimiter("\\Z").next();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue