Always throwing java.nio.file.NoSuchFileException

1,070 views
Skip to first unread message

Pedro Pinto

unread,
Nov 7, 2017, 7:10:03 AM11/7/17
to vert.x
Hello,
I'm trying to write to a file but no matter the file or the permissions I have (e.g., 777) I always get the exception java.nio.file.NoSuchFileException.

Another issue I have is that the documentation for the method writeFile (from the class FileSystem) says that it creates the file but that doesn't happen. I created the file manually but the error continues.

This is my code:


fs.writeFile("~/somefile.txt", Buffer.buffer("Hello"), function(res, res_error) {
 
if(res_error === null) {
 console
.log("Ok!");
 
} else {
 console
.log("Oh, oh... " + res_error);
 
}
});

Am I missing something? Thank you

Jez P

unread,
Nov 7, 2017, 7:27:01 AM11/7/17
to vert.x
What happens if you don't use ~ but give the full path to the file?

Pedro Pinto

unread,
Nov 7, 2017, 9:35:27 AM11/7/17
to vert.x
It works ;) That was my mistake. Thank you

Alexander Lehmann

unread,
Nov 7, 2017, 10:12:46 AM11/7/17
to vert.x
I think the ~/ shortcut is expanded by the shell so that this does not work when you use it in any normal program

You have to use something like getenv("HOME")+"/somefile.txt"
Reply all
Reply to author
Forward
0 new messages