Scanner nextLine() bringt Dateipfad

hk

Bekanntes Mitglied
Ich habe ein seltsames Problem mit dem Scanner. Die nextLine()-Funktion retourniert den Dateipfad anstelle der ersten Zeile. In der Datei steht: "F:/Datensicherung/" im UTF-8-Format:
Java:
public String getBackupPath() {
    backupPath = "";
    try {
      Scanner sc = new Scanner("C:\\Users\\user\\AppData\\Datensicherung\\BackupPfad.txt");
      if (sc.hasNextLine()) {
        backupPath = sc.nextLine();        <-- HIER wird der Dateipfad geliefert
      }
      sc.close();
    } catch (Exception exception) {
      System.out.println(exception);
    }
    return backupPath;
  } //END getBackupPath ********************
 
Ich habe ein seltsames Problem mit dem Scanner. Die nextLine()-Funktion retourniert den Dateipfad anstelle der ersten Zeile. In der Datei steht: "F:/Datensicherung/" im UTF-8-Format:
Java:
public String getBackupPath() {
    backupPath = "";
    try {
      Scanner sc = new Scanner("C:\\Users\\user\\AppData\\Datensicherung\\BackupPfad.txt");
      if (sc.hasNextLine()) {
        backupPath = sc.nextLine();        <-- HIER wird der Dateipfad geliefert
      }
      sc.close();
    } catch (Exception exception) {
      System.out.println(exception);
    }
    return backupPath;
  } //END getBackupPath ********************
Problem gelöst: Habe vergessen das ich "new Scanner(new File("...")) schreiben muss!
 

Zurück
Oben