Simpan array ke file TXT

Permisi gan, mau nanya bagaimana caranya menyimpan data array ke file TXT serta bagaimana cara menampilkannya kembali? Thanks.

avatar Romi2311
@Romi2311

30 Kontribusi 1 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

Jawaban Terpilih

Coba ini gan:

Untuk Save TXT file: <pre> List&lt;String&gt; lines = Arrays.asList("The first line", "The second line"); Path file = Paths.get("the-file-name.txt"); Files.write(file, lines, Charset.forName("UTF-8")); //Files.write(file, lines, Charset.forName("UTF-8"), StandardOpenOption.APPEND); </pre> sumber: [link]https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to-it-in-java [/link] [link]https://www.youtube.com/watch?v=k3K9KHPYZFc [/link] [link]https://www.youtube.com/watch?v=xDetrVqsqSk [/link]

Untuk Show TXT file:

<pre> BufferedReader abc = new BufferedReader(new FileReader(myfile)); List&lt;String&gt; lines = new ArrayList&lt;String&gt;();

while((String line = abc.readLine()) != null) { lines.add(line); System.out.println(data); } abc.close();

// If you want to convert to a String[] String[] data = lines.toArray(new String[]{}); </pre> sumber: [link]https://stackoverflow.com/questions/10257981/read-text-file-into-an-array [/link] [link]https://stackoverflow.com/questions/19844649/java-read-file-and-store-text-in-an-array [/link] <a href='https://www.youtube.com/watch?v=_6_zAtrWl8o '>https://www.youtube.com/watch?v=_6_zAtrWl8o </a> <a href='https://www.youtube.com/watch?v=hQut8sCGcDw '>https://www.youtube.com/watch?v=hQut8sCGcDw </a>

happy googling :)

avatar keccikun
@keccikun

368 Kontribusi 197 Poin

Dipost 6 tahun yang lalu

Thanks gan

avatar Romi2311
@Romi2311

30 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban