Create folder in a mapped network drive using Java - java

I'm trying to create a folder to a mapped network drive Z: using Java
Unfortunately the file is not getting created. This is what I'm doing:
File file = new File("Z:/file1");
file.mkdir();
This code works when not using mapped network drive. This is on Windows environment.
Any ideas?

Ok I figured this out. Tomcat is running under Windows 2003 Server. According to what I found is that when Tomcat is started under the Windows Services, for some reason it doesn't have access to the mapped network drive.
Using UNC paths worked for me.
File myFile = new File("\\\\server\\shared\\input");
myFile.mkdir();
I was able to create a folder on the mapped network drive on that server.

Related

Java File Object for a File in ADLS Gen2

I have a tool that works for on-premise data upload. Basically, it reads the file from local system i.e.(on-premise: Linux or Windows) and send it over to a location.
It makes use of Java File class. eg: new File("/dir/file.txt")
I want to make use of the same code for input files on ADLS Gen2. I would be running the code on Azure Databricks and stuck with getting the File object for the files in ADLS Gen2. I am using wasbs protocol for making the File object, but it is coming as null as Java is not recognizing the directory structure.
If this tool is using local file access, then you can still use it by mounting the ADLS as DBFS to some location, like, /mnt, and then use this mount locally as /dbfs/<mount-point> (/dbfs/mnt/).

Read files from another pc Using JAVA and apache tomcat

File[] files = new File("\\172.22.1.77\FolderName").listFiles();
I'm trying to read some files from another IP on my network from shared folder 'FolderName'.
It works locally from eclipse.
But when it deployed on apache tomcat, it doesn't work.
Any help about this ?
Check if the user under which Tomcat is running has permissions to access the folder

Do we need seperate file path for window and linux in java

I have a file on linux ubuntu server hosted with path name /home/kishor/project/detail/.
When I made a web app in window to upload and download file from specified location i used path "c:\kishor\projects\detail\" for saving in window.
For my surprise when i used window file path name in my server i am still able to get files and upload them, i.e, "c:\kishor\projects\detail\".
Can anyone explain why it is working (as window and linux both use different file path pattern).
I've seen this work too. What linux does is create a file whose name is literally c:\kishor\projects\detail\
If you say, you can "upload" files... perhaps there is now a new folder structure.
Some months ago i saw a similar thing: Under /home/webadmin was an new structure "/c:/Users/...."

Zipping a folder in remote machine running app server through J2EE app

I am working on a zipper J2EE application. This application requires the following:
The application has to zip a folder in remote machine where app server is running so that other applications can directly download this zipped folder instead of downloading each file one by one.
I am able to do this in my local machine using absolute path don't know how to go ahead with remote machine.
Code i'm using for zipping in local machine:
File file = new File(myFolderPath);
int index = myFolderPath.lastIndexOf("/");
String folderName =myFolderPath.substring(index);
String folderPath = myFolderPath.substring(0, index);
File outFolder = new File(folderPath + folderName + ".zip");
if (!outFolder.exists()) {
zip(file, outFolder);
}
Here myFolderPath is a string. But how should i go ahead if it is a URL?
Thanks in advance.
URLs don't allow directory listings, so this is not possible. You will need absolute paths on the server, too, or convert the URL to an absoltue path on the server, maybe by replacing a http://server/ with the root folder of the webapp.
My suggestion would be to use a message driven bean for this case. You have a MDB that listens to incoming msgs on a JMS queue. The message has the folder to zip. The message bean then will call a helper that would zip the folder that is provided to the MDB. I'm basing this on the details available in your question. There is a app server running and you want the zipping action to happen on that server machine. It will be much more efficient and clean in my opinion.
The application has to zip a folder in
remote machine where app server is
running
I guess you have fair idea about path to the directory you wanted to zip. So code same thing what you have done locally but in servlet, create zip fiel and write the content of the zip in output stream of HttpServletResponse in order to download it.

Java Web Start: How to write files to windows UNC Path?

I have an Java application for copying large amounts of data from users' workstations to a server. The java.io.File class is supposed to work with UNC paths very well and in fact it does but only when I run the app in standard execution model.
When the application is launched via Web Start I get a FileNotFoundException when trying to open a FileOutputStream with "The network path was not found" in message. Again everything works fine when I download the jar to the PC and lauch it from command line.
My app is signed and i define all-permissions in JNLP.
Edit: I have also discovered that when I map the UNC path to a drive letter it works too.
There is no solution to this. I ended up mounting the path as a named volume and using it trough the volume.

Categories