Write and read to .txt file JAVA | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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

31st Dec 2017, 7:56 PM
Duncan Skilton
Duncan Skilton - avatar
3 Respostas
+ 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!
31st Dec 2017, 10:31 PM
Jonas Schrƶter
Jonas Schrƶter - avatar
+ 1
For tab space, use "\t" between your Strings!
31st Dec 2017, 10:33 PM
Jonas Schrƶter
Jonas Schrƶter - avatar
+ 1
Thatā€™s great, thank you. Iā€™ll give it a try later today šŸ‘šŸæ
2nd Jan 2018, 7:58 AM
Duncan Skilton
Duncan Skilton - avatar