Postingan lainnya
Simpan array ke file TXT
Permisi gan, mau nanya bagaimana caranya menyimpan data array ke file TXT serta bagaimana cara menampilkannya kembali? Thanks.
2 Jawaban:
Jawaban Terpilih
Coba ini gan:
Untuk Save TXT file: <pre> List<String> 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<String> lines = new ArrayList<String>();
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 :)