Answers for "writing to and from a file java"

5

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);
}
Posted by: Guest on April-09-2020

Code answers related to "writing to and from a file java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language