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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...