“Java salvar arquivo” Respostas de código

Java salvar arquivo

//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

Escreva o arquivo 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 salvar arquivo


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

Respostas semelhantes a “Java salvar arquivo”

Perguntas semelhantes a “Java salvar arquivo”

Mais respostas relacionadas para “Java salvar arquivo” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código