Answers for "java how to create a file and write to it"

3

java create file

File filename = new File(filepath)
Posted by: Guest on March-09-2020
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 "java how to create a file and write to it"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language