Я пытаюсь загрузить свои данные для моей программы из текстового файла с именем «inData.txt» и вывести его в файл «out.txt», в основном имитируя сохранение. Проблема в том, что когда я запускаю этот код через мой графический интерфейс, он не загружается в текстовые области, но сохраняет его. Я не знаю, если это проблема с моим кодом GUI или кодом в самом файле Лиги.
Я попытался проверить, не изменяется ли текстовый файл, но он не работает, но код работает без ошибок.
//League.java
private static final String READ_FILE="inData.txt";
private static final String OUT_FILE="out.txt.";
public void readFromFile() //throwsIO exception /take from file into arraylist
{
//reading the inData.txt file and loading the arraylist
//with each instantiated object from the data
try
{
Scanner in = new Scanner(new File(READ_FILE));
//loop through the file and read each valie and create an object
while(in.hasNextLine())
{
String name = in.nextLine();
System.out.println ("read name: " + name);
String coach = in.nextLine();
System.out.println ("read coach: " + coach);
int teamID = in.nextInt();
System.out.println ("read team ID: " + teamID);
int wins = in.nextInt();
System.out.println ("read wins: " + wins);
int losses = in.nextInt();
in.nextLine();
System.out.println ("read losses: " + losses);
String player1 = in.nextLine();
System.out.println ("read player 1 name: " + player1);
String position1 = in.nextLine();
System.out.println ("read player 1 position: " + position1);
Player p1 = new Player(player1, position1);
String player2 = in.nextLine();
System.out.println ("read player 2 name: " + player2);
String position2 = in.nextLine();
System.out.println ("read player 2 position: " + position2);
Player p2 = new Player(player2, position2);
String player3 = in.nextLine();
System.out.println ("read player 3: " + player3);
String position3 = in.nextLine();
System.out.println ("read player 3 position: " + position3);
Player p3 = new Player(player3, position3);
//create and Item object
Team newTeam = new Team(name, coach, teamID, wins, losses, p1, p2, p3);
league.add(newTeam);
}
}
catch(IOException e)
{
System.out.println ("Error with file loading");
}
}
Ожидаемый результат от readFromFile () - получить информацию из inData.txt и импортировать ее в графический интерфейс.