Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

parameter passing - java nio Files.write() method not working

Okay, so I'm trying to use the new Files.write method in Java. Here is a link

It says the StandardOpenOption is optional, but everytime I leave it blank, and even when I do put something in there I get a compiler error. For Example...

try{
 Files.write("example.txt",byte[] byteArray);
 }
  catch(Exception e){}

will result in The method write(Path, byte[], OpenOption...) in the type Files is not applicable for the arguments (Path, String)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This has nothing to do with NIO and everything to do with language syntax. You have:

Files.write("example.txt",byte[] byteArray);

I don't know what your intention is with that, but you can't declare a variable in a function parameter list like that. You probably mean something like:

byte[] byteArray = ...; // populate with data to write.
Files.write("example.txt", byteArray);

For a more formal view, dig around through the JLS, starting at JLS 15.12. There is ultimately no ArgumentList pattern in the language that can accept a LocalVariableDeclarationStatement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...