+ 1
Write and read to .txt file JAVA
I have a text file which has several columns of text. I guess I need to import the text as an array but can someone point me in the right direction? Also, how do I write to file separating strings with a tab size space? Thank you
3 Antworten
+ 1
Read:
You could use this:
Scanner scanner = new Scanner(new File (HeresThePath);
while (scanner.hasNextLine(){
System.out.println(scanner.nextLine();
}
scanner.close ();// this is very important!
Write:
BufferedWriter writer = new BufferedReader(new FileReader (PATH));
writer.write ("A Line");
writer.newLine ();
writer.write ("Another Line");
writer.close (); // this is very important!
+ 1
For tab space, use "\t" between your Strings!
+ 1
That’s great, thank you. I’ll give it a try later today 👍🏿