这里有一个摘自这里的片段:
import static java.nio.file.StandardOpenOption.*;
Path logfile = ...;
// Convert the string to a
// byte array.
String s = ...;
byte data[] = s.getBytes();
try (OutputStream out = new BufferedOutputStream(
logfile.newOutputStream(CREATE, APPEND))) {
...
out.write(data, 0, data.length);
} catch (IOException x) {
System.err.println(x);
}
但是我不能用 newOutputStream 方法编译日志文件(它是一个 Path 对象)......只能用 Files.newOutputStream(path,StandardOpenOption..);