Java 7 way to write a file

2019-03-06 15:49发布

问题:

I have managed to read a file by

Files.copy(Paths.get(file.toURI()), System.out);

How do I write a sequence of characters to a file? I see no effect from

Files.copy(new ByteArrayInputStream(content.getBytes()), Paths.get(file.getName()))

and it looks ugly.

回答1:

I have succeeded this way

Files.write(Paths.get(file.getName()), content.getBytes());


标签: stream java-7