Java Buat file txt
File myObj = new File("path");
myObj.createNewFile();
FileWriter myWriter = new FileWriter("path");
myWriter.write("text");
myWriter.close();
Vails
File myObj = new File("path");
myObj.createNewFile();
FileWriter myWriter = new FileWriter("path");
myWriter.write("text");
myWriter.close();
PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
@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);
}
File file = new File("Z:\\results\\results.txt");
public void whenWriteStringUsingBufferedWritter_thenCorrect()
throws IOException {
String str = "Hello";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(str);
writer.close();
}