Answers for "export text file java"

6

java create txt file

File myObj = new File("path");
myObj.createNewFile();
FileWriter myWriter = new FileWriter("path");
myWriter.write("text");
myWriter.close();
Posted by: Guest on June-25-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"

Java Answers by Framework

Browse Popular Code Answers by Language