0

Here there is a snippet taken from here:

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);
}

However I cannot compile the logfile (which is a Path object) with newOutputStream method... only with Files.newOutputStream(path,StandardOpenOption..);

Rollerball
  • 12,618
  • 23
  • 92
  • 161
  • _However I cannot compile the logfile (which is a Path object) with newOutputStream method... only with Files.newOutputStream(path,StandardOpenOption..);_ Ok. So? What is the question? – BackSlash Jun 16 '13 at 12:27
  • Taken from where? No link. Did you mean [here](http://docs.oracle.com/javase/tutorial/essential/io/file.html)? If so, the simple answer is that the tutorial is wrong. – user207421 Jun 17 '13 at 06:40

1 Answers1

0

Path only contains information about where a file (or other thing) is located, it does not provide any information on how to process it. As you know the Path is a file then you can use the File class to process it, in this case to open a stream on it.

In language terms Path does not have a newOutputStream method so it will fail to compile.

From Oracle documentation on Path

Paths may be used with the Files class to operate on files, directories, and other types of files.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117