I asked a previous question about if it were possible to get the absolute filepath of a file using the html5 file API. Due to browser security issues, it is not.
For an internal project, I need to be able to move files from one computer's machine to shared storage. A 'controller' does the moving, as the user's don't have direct access to the storage volume.
Is it possible to pull the a file's absolute path using flash or a java applet in a browser? If so, how would this be done, or if you could point me to relevant documentation, that would be great.
A trusted applet could provide the information, with a little help from the end user.
Offer the user a JFileChooser to navigate to the files/directories of interest. Once the user has selected a File, call JFileChooser.getSelectedFile() for the details.
You may need to add Policy File permission. Please refer > http://docs.oracle.com/javase/tutorial/security/tour1/step2.html. Hope that helps
Related
Disclaimer:I know that this is something that is covered very early in learning Java, however, I am just a hobbyist and I am self-taught. I am only as good as the information I find online is. Please do not be derisive or condescending. We were all new at one time.
As mentioned, I have a written a Java Form app. What it does it takes user input and writes it to an Excel file. How can I dynamically reference a file (the Excel, in particular) that is on each users' computer, found in a different directory but not have to hardcode each user's exact file path and distribute individually?
Thanks!
I think you are looking for user.home property.
System.getProperty("user.home");
Which will give you, say, c:\users\mk
and then you can append your path to that.
You could have the application ask the user for the path.
As part of the application configuration have the user define an environment variable using a known name with either the desired directory or the install directory (then use the variable to derive the desired directory).
for example:
tell the user to define BLAMMY_HOME which contains the install location of your software (named BLAMMY).
derive the desired directory by concatinating the value of BLAMMY_HOME and "/desired/directory/name".
or
have the user define BLAMMY_SPOT which contains the full path the the desired directory.
use the value of BLAMMY_SPOT in your application.
Defaulting to using user.home is fine, but I (personally) do not like that technique (as a user).
Take an example of 2 users
UserA path: /opt/file/directories/target (contains the excel file)
UserB path: /opt/directories/target (contains the excel file)
There's absolutely no way to find the target directory (except searching for it, but then you might find another one) unless the application has access to some out of band information. For example, Java offers the user.home property
String pathPrefix = System.getProperty("user.home");
so you can use that and make your target directory relative to that.
That's the whole purpose of applications having installation/working directories. As another example, take the Windows Registry. Imagine you had to download a patch from the internet. The patch itself wouldn't be able to check all the paths on the file system until it found yours (each user has a different one). Instead, it can find that path from the Windows Registry (or something comparable depending on the application).
Can i access my local file system files with my browser? I think it is possible, I found one mozilla firefox plugin which does the same.
As per my understanding, the way upload functionality of a browser works, in the same way we can do traversing of files.
Please provide provide me some link to know about the "upload functionality" of a browser, how does it contact to the filesystem to upload any file from a given path.
Or can I write ay client side script which can do traversing?
If you're just wanting to let the client upload a file, there's no need for plugins or Java or anything such. Just use FileUpload in a form.
When we want to load a static file e.g. a picture, a sound file, a file containing information about a game map,... we can store them as resources in jar file and use getClass.getResource("images/splash.png") (also getResourceAsStream) to load and use them. But when we want to read and write into a file like settings file, I don't think using resources is a good way, because i think resources are designed to store read/only files that are not supposed to change, like splash screen image or a game's background music; These are my reasons to think this way:
That is why return value of getResourceAsStream is an instance of InputStream and we don't have a similar function which gives us an OutputStream, because we're not supposed to alter resource files.
Writing into resources changes program .jar file and i guess it's not a good thing at all; Because if we do so: we can't use check-sums to verify file, if we are a limited user and system administrator doesn't give us write permission we can't make changes into main .jar file, user-specific preferences are hard or impossible to implement,...
So, my questions are:
Which parts of my thoughts and assumptions are right or wrong?
If they're right what is the best(I mean short and portable between OSs and Computers) way to store files like that? (Application setting/preferences, A game save file, ...)
(#Some user who may wants to mark this as duplicate: I don't think my question is a duplicate, i searched in the site, I admit it has some common parts with some questions but it's not duplicate!)
Your three observations in #2 above are valid reasons not to store settings in a resource file, regardless of the APIs provided.
There are a variety of ways to save settings in Java, including:
The Java system property "user.home" provides the user's home directory, to which the user should have write access. You can create an application-specific subdirectory underneath it.
Java provides a Preferences API. This may store settings in a directory or (on Windows) in the registry.
OSGI provides a preferences API.
If you're using the Eclipse RCP, you can write to the configuration directory using a ConfigurationScope. See the Eclipse FAQ "What is a preference scope").
I have a requirement to process an external request to populate a HTML form with the parameters mentioned in the URL. This part is working fine. However, the URL also contains paths to files present on the client machine and I want to upload those files from the client machine to the server without user interaction.
Since it is not possible with HTML/Javascript to programatically select files, I tried using the Applet approach using JUpload. However, I am not able to figure out, how to preselect a file on applet initialization. It is not necessary to upload the files right away, but I want atleast to select the files automatically. User can review the info and then submit the form. and files in the applet.
Is it possible with this library? Or direct me to some better path
OK, so I found my answer in a different library with similar name. With Smartwerkz JUpload we can pass a parameter preselectedFiles="filePath" and autostartUpload=true to preselect files and auto upload files without user interaction. I hope it will help someone someday.
I am using Java language
What I want is that Can any one help me to write a code that
When i click on delete option of any file or folder I get notify before delete that I ma deleting a file Whether I want to continue ?
I have seen many examples that notify after the file is deleted.
One thing I want to make clear is as I click on file placed Desktop or My document directory I must get notify that
You are deleting a file .do you want to continue ?
What I really need is I want the exact answer or code
Please help
I shall be very thankful to you
No, this is not possible in Java. The operating system handles the file access, and another process is not capable of preventing the system denying access to those files. The only way you could do this is by having a file system written in Java (say, a loopback mounted WebDAV share) to which you could intercept the file requests with this kind of information. But not only would this be difficult to achieve, it also would only work if all of the access you are doing is via your loopback mounted system; it wouldn't work for files located on the disk or from other network shares.
So, in summary, you cannot do this with any programming language without writing your own filesystem and using that to intercept requests.