public class DateiLesen {
private String text;
private String dateiname;
public DateiLesen(String dateiname) {
this.dateiname = dateiname;
}
public DateiLesen() {
}
// getter/setter entfernt
public void fileToString() throws FileNotFoundException {
File file;
Scanner scan;
StringBuilder sb = new StringBuilder();
file = new File(this.dateiname);
scan = new Scanner(file);
while (scan.hasNext()) {
sb.append(scan.nextLine());
}
scan.close();
this.text = sb.toString();
}
}
public class Main {
public static void main(String[] args) {
DateiLesen dl = new DateiLesen("/home/jo/Dokumente/wortliste.txt");
try {
dl.fileToString();
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(dl.getText());
}
}