📜  java 创建 txt 文件 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:10.104000             🧑  作者: Mango

代码示例3
@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);
}