Writing file outside VertX home folder problem

365 views
Skip to first unread message

Eugene Strokin

unread,
Feb 5, 2015, 11:23:49 PM2/5/15
to ve...@googlegroups.com
Hello,
I'm trying to write a file:

vertx.fileSystem().writeFile("/opt/myfile", data, new Handler<AsyncResult<Void>>() {
 
@Override
 
public void handle(AsyncResult<Void> ar) {
   
System.out.println("File is written: "+ar.cause());
 
}
 
});


and I'm getting:

File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile


But if I change the path to the folder the module is running from, it creates the file with no problem.

I've check permissions, they are the same.

Should I be able to write outside the module folder? If not, why, and I really need it, so how can I do this?


Thanks,

Eugene

Mumuney Abdlquadri

unread,
Feb 6, 2015, 2:51:01 AM2/6/15
to ve...@googlegroups.com
Are you able to write in any other location apart from /opt/  and module folder?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Fox

unread,
Feb 6, 2015, 2:56:57 AM2/6/15
to ve...@googlegroups.com
On 06/02/15 04:23, Eugene Strokin wrote:
Hello,
I'm trying to write a file:

vertx.fileSystem().writeFile("/opt/myfile", data, new Handler<AsyncResult<Void>>() {
 
@Override
 
public void handle(AsyncResult<Void> ar) {
   
System.out.println("File is written: "+ar.cause());
 
}
 
});


and I'm getting:

File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile
File is written: org.vertx.java.core.file.FileSystemException: java.nio.file.NoSuchFileException: /opt/myfile


But if I change the path to the folder the module is running from, it creates the file with no problem.

I've check permissions, they are the same.


/opt on unix/linux is generally used for installing software packages system wide. It's not usually something a normal user would have permission to write in. So I'd be surprised if you have permission to write there unless your system is setup strangely, or you're running as root, which I hope is not the case ;)

Should I be able to write outside the module folder? If not, why, and I really need it, so how can I do this?


Thanks,

Eugene

--

Eugene Strokin

unread,
Feb 6, 2015, 8:34:25 AM2/6/15
to ve...@googlegroups.com
Yes, I was able to write to other locations, and further investigation shows, that I'm able to write to any folder as long as it exists.
So, in my case if /opt folder is present, I can write file to it. If it doesn't exists, Vert.x doesn't create it for me and fails to write the file.
I guess I need to manually check if all folders in the location are there, and if not create them, before writing the file.
Or is any better way to do this?

Thank you,
Eugene

Tim Fox

unread,
Feb 6, 2015, 11:02:14 AM2/6/15
to ve...@googlegroups.com
On 06/02/15 13:34, Eugene Strokin wrote:
Yes, I was able to write to other locations, and further investigation shows, that I'm able to write to any folder as long as it exists.
So, in my case if /opt folder is present, I can write file to it. If it doesn't exists, Vert.x doesn't create it for me and fails to write the file.

Yes, writeFile writes a file, it does not create directories. If you want to create directories you can use mkdirs.

Eugene Strokin

unread,
Feb 6, 2015, 11:56:10 AM2/6/15
to ve...@googlegroups.com
Thank you Tim,
I'm doing:

            //Create all parent folders if needed
     
int ind=fileName.lastIndexOf('/');

     if(ind>=0){

          vertx.fileSystem().mkdirSync(fileName.substring(0, ind), true);

     }

     //write the file

     vertx.fileSystem().writeFile(fileName, data, new Handler<AsyncResult<Void>>() {

           @Override

           public void handle(AsyncResult<Void> ar) {

                  System.out.println("File is written: "+ar.cause());

           }

     });

and everything works now.

BTW: the system is meant to hold a lot of traffic, so I'm trying to make everything as asynchronous as possible.

I wander if this: 

vertx.fileSystem().writeFile(fileName, data, new Handler<AsyncResult<Void>>() {
       
   
@Override

          public void handle(AsyncResult<Void> ar) {

//ignoring, have nothing to do here

          }

    });

would work the same as this:

vertx.fileSystem().writeFileSync(fileName, data);


Or writeFileSync is actually blocking?

Thank you,

Eugene

Reply all
Reply to author
Forward
0 new messages