“Java Simpan File” Kode Jawaban

Java Simpan File

//Create a text file and write to it immediately
//stackoverflow

PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
Annoying Ant

Tulis file java

@Test
public void givenUsingJava7_whenWritingToFile_thenCorrect() 
  throws IOException {
    String str = "Hello";
 
    Path path = Paths.get(fileName);
    byte[] strToBytes = str.getBytes();
 
    Files.write(path, strToBytes);
 
    String read = Files.readAllLines(path).get(0);
    assertEquals(str, read);
}
Colorful Cottonmouth

Java Simpan File


public void saveReport(KmaxWidget widget)
    throws IOException
{
    final String content = report.getProperty("TEXT");
    final Path path = Paths.get("logKMAX.txt");

    try (
        final BufferedWriter writer = Files.newBufferedWriter(path,
            StandardCharsets.UTF_8, StandardOpenOption.CREATE);
    ) {
        writer.write(content);
        writer.flush();
    }
}

Attractive Addax

Jawaban yang mirip dengan “Java Simpan File”

Pertanyaan yang mirip dengan “Java Simpan File”

Lebih banyak jawaban terkait untuk “Java Simpan File” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya