Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

write 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);
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #write #file #java
ADD COMMENT
Topic
Name
1+1 =