Mám 2 metody ve třídě, jedna vepíše něco do souboru a druhá má najít příslušnou oblast dále vypsat ID klávesy, ale chyba je, že vyhledávání nefunguje, tak jak má, co s tím?
package GamePackage;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.text.html.HTMLDocument.HTMLReader.CharacterAction;
public class Database{
private File file;
private BufferedWriter bw;
private BufferedReader br;
private int UpButton=KeyEvent.VK_UP;
private int DownButton=KeyEvent.VK_DOWN;
private int LeftButton=KeyEvent.VK_LEFT;
private int RightButton=KeyEvent.VK_RIGHT;
private int ShootButton=KeyEvent.VK_SPACE;
private int FrameSize=800;
/*****************************************************
* Constructor
*****************************************************/
public Database(){
file=new File("D:\\test.txt");
MakeOrReset();
System.out.println(GetKeyID("UpButton"));
}
/*****************************************************
* MakeOrResetmethod
*****************************************************/
private void MakeOrReset(){
try {
if (!file.exists()) {
file.createNewFile();
}
bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));
bw.write("UpButton "+UpButton);
bw.newLine();
bw.write("DownButton "+DownButton);
bw.newLine();
bw.write("LeftButton "+LeftButton);
bw.newLine();
bw.write("RightButton "+RightButton);
bw.newLine();
bw.write("ShootButton "+ShootButton);
bw.newLine();
bw.write("FrameSize " +FrameSize);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public int GetKeyID(String ButtonName){
int IDNumber=0;
try{
br = new BufferedReader(new FileReader(file.getAbsoluteFile()));
String line = null;
while ((line = br.readLine()) != null) {
Scanner read = new Scanner(line);
String word1 = read.next();
String word2 = read.next();
IDNumber = Integer.parseInt(word2);
read.close();
if(ButtonName==word1)
break;
}
br.close();
}catch(IOException e){}
return IDNumber;
}
}