So, I'm trying to create this app, and am still in the beginning, but every time i run it and try to write in the file Dictionary.txt, the file will be completely empty. It would work in this other thing I've made, but here it just runs well, gets terminated, and when I open the file it is blank, unwritten. Currently on Eclipse Mars, and it gives me no errors (apart from the random object not being used, but I plan to use it later on.)
package mainPackage;
import java.util.Random;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.BufferedWriter;
public class MainClass {
private static FileWriter fw;
private static BufferedWriter out;
private static Scanner input;
private static Scanner file;
private static Random slc;
public static void main(String[] args) throws IOException{
fw = new FileWriter("C:/Users/ALAN_BARE/Desktop/Dictionary.txt" , true );
input = new Scanner(System.in);
file = new Scanner(new File("C:/Users/ALAN_BARE/Desktop/Dictionary.txt"));
out = new BufferedWriter(fw);
slc = new Random();
String engword;
String gerword;
String response;
System.out.println("What do you want to do, register words or play the game?");
response = input.nextLine();
if(response.contains("register")){
System.out.println("Type yor english word:");
engword = input.nextLine();
System.out.println("Type the translation in German:");
gerword = input.nextLine();
out.write(engword);
out.write(gerword);
if(file.hasNextLine()){
out.newLine();
out.newLine();
out.write(engword);
out.write(" " + gerword);
}
else{
out.write(engword);
out.write(" " + gerword);
}
}
else if(response.contains("Register")){
System.out.println("Type yor english word:");
engword = input.next();
System.out.println("Type the translation in German:");
gerword = input.next();
if(file.hasNextLine()){
out.newLine();
out.newLine();
out.write(engword);
out.write(" " + gerword);
}
else{
out.write(engword);
out.write(" " + gerword);
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire