I have a jsp form with a download button.Whenever user clicks that button it will download a pdf file and popups that.I'm using chrome browser. My download location is
C:\Users\gt\Downloads
For this I have used the following code to open from that location.
String filePath=System.getProperty("user.home")+"\\Downloads\\"+pdfname;
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " +filePath);
Now when user clicks the download button the pdf file will get save in that location by the name like F90CR0010-HBR-C-4.pdf and my code will open this correctly.
When the user clicks the download button again for second time it will save as like F90CR0010-HBR-C-4 (1).pdf But my code will open the old previous file only.Because the name is that only.I need to open the latest downloaded file.
Any Idea of how to open the latest downloaded file??I have a idea that I can add the current time to my pdfname and so it will be unique.But my requirement is that pdf name should be like this only.
If you know what the base file name would be (in your case F90CR0010-HBR-C-4.pdf ) then you can use a simple regex to check for strings of the form F90CR0010-HBR-C-4\(\d+\).pdf . If you find one then just figure out which one has the biggest number and open that one.
Its not really pretty, but it works. Also, technically this can be "hacked" by making your own file called F90CR0010-HBR-C-4(999999).pdf, but I would guess you dont really care.
Related
I want to get the last downloaded file name to read it from java. I am working with selenium and need to get the last downloaded file name from chrome download list or from my download directory.
You can open downloads page in the new tab. The page is using shadow-root, so you have to do a little tricks to access the elements. Please, see the answer on this page, especially the JavaScript example. It will help you get around shadow-root and access the elements you need
I am trying to write a java program that uses selenium to perform web actions. In the case of uploading a video there is a frame where the user clicks that brings up the File Explorer for Windows. I have not been able to find anything that will help me in getting the focus to the File Explorer to select a file. There is no "browse" on the page with a textbox for me to just send a filename to.
Here is what the page looks like:
I would try using Selenide because it has a pre-canned upload utility that might save you some time/effort. See the command .uploadFromClasspath in the docs. One of the project videos/pages shows a little more detail on how to do it.
I've not actually tried it, but if this works for you and you figure it out, please share.
What I have done in the past is to use the "Apache HttpUtils" class to simulate the upload action from my test. All you need is the upload URL, and the HTML page usually provides that. That might also work for you.
I need an Open Dialog File Chooser that opens files for reading only. I want user to only be able to click on a file name to select it with no option to edit the name. Users should be able to browse to other folders, though.
I'm on Ubuntu 10.11 with the latest Java (as of January).
TIA.
This example shows that editable file names is a feature of the FileChooserUI implementation. For example, com.apple.laf.AquaFileChooserUI does not have this capability. The tutorial does not suggest any way that it can be changed, but this FileBrowser may suggest a custom alternative.
I have URL that gets called from my java app that returns the save/open dialog for an Excel file.
At the moment, it opens in a new tab but I want to return the dialog box in the same window. I do not know the file name as it is dynamic and changes based on the parameters passed in.
I also do not want to save it somewhere as I want the user to have the choice of opening or saving.
Is there anyway of doing this in Java? I've only seen examples where the file name is known.
EDIT
The URL is hitting a CGI Script
Create a File object in your app from the url, store it in a temporary location then ask Excel to open it for you.
I'm having the following problem with a JFileChooser: I create a save dialog and then when I'm trying to save a file, I'm entering a file name into the field and click "Save". Suppose that the directory, which I try to save my file to, contains a subdirectory, which is named exactly like the entered name. In this case JFileChooser opens it instead of saving my file, and I don't know how to make it save a file instead of opening the directory with the same name.
I tried to do something with the file filters, with approveSelection() and changed UI from Windows to default - nothing helps. How to make JFileChooser stop opening a folder and save the file? Is there some way to modify the behavior of the button or am I just doing something wrong?
Update:
To be clear: I'm not trying to save a file with the same name, I'm just trying to make JFileChooser get the path so I could append an extension to it. However, I checked Word and Photoshop, neither of them is able to do what I request, so I guess I wish to make everything too perfect. But if there's a way to do what I want, I'll still be glad to hear the solution.
Neither Windows nor Linux allow file names and directory names to be the same in the same directory as far as I know. Under Linux of course they can be the same with different case lettering :)