How to create a .lnk file on the desktop using Java? - java

How can I create a .lnk file using Java? such as I want to create a .lnk file on my desktop which opens the following directory C:\Windows\System32\calc.exe. I have found this website but it is for creating an URL for the website shortcut. it basically write out 2 lines ([InternetShortcut] and
URL = XXXXXX.com) by using FileWriter and save it as .URL file. but it seems not working with lnk extension.

Related

i am not able to view my downloaded file in downloads folder using selenium java

[Screenshot displaying the downloaded file in a window[][1]1i am not able to access my downloaded file which i opened in a new small window popup using selenium java and also i am not able to find it in downloads folder.
When i click on a download button-->the file gets downloaded with an icon of word in a new small popup browser window-->but it does not move into the downloads folder. Testcase passes but i am not able to validate.In that browser window i am not able to find any elements....only .... tags are displayed.. While doing it in manual way i am able to view it in downloads folder.
Kindly advise me what should be done.
you are coding in java language,
so, use method exists() which will return boolean value.
You must know your Downloaded file name along with exact download path,
String FileName = "YOUR_FILE_NAME";
File tmpDir = new File("C:\Users\a.k\Downloads\"+FileName);
if(tmpDir.exists())
System.out.println("File Downloaded");
System.out.println("File Not Downloaded");

Get path from inside a JAR File (for system property in selenium)

I am using Selenium Webdriver in Java for creating accounts from a excel file for a mediawiki software. I am working with eclipse.
When i try to export my project to a runnable jar file, there are some problems.
I have a file named "geckodriver.exe" im my resources folder (projectname/src/resources/geckodriver.exe)
All i want to do is to set a system property for selenium, so the user not have to manually choose the gecko driver file for working correctly with selenium.
This is my actual code, working inside eclipse
String filename = "geckodriver.exe";
File geckodriverFile = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
geckodriverPath = geckodriverFile.getAbsolutePath() + "\\resources\\" + filename;
And finally i want to set the system property
System.setProperty("webdriver.gecko.driver", geckodriverPath);
How can i achieve this to work inside a jar file?

best way to load external files in j2EE?

I am trying to deploy a REST web service. I use glassfish as a web server.
I have a problem when i try to open an external file. in other words I want to read a file that is in the web-inf folder named "config.xml".
When I used a Java application (not web application), I used the following code to open the file but now it does not work
String path = new File (".") GetCanonicalPath () + "/ config.xml".
Cordially
I guess this line can be useful to you:
File image = new File(req.getServletContext().getRealPath("/") + "/carrousel/"+ req.getParameter("fileName"));
I use it to create a new File in the server.

Deleting a file, opended by an external application, after closing it

I'm creating a pdf file in my java program.
After having it created to a specified Path, I'm opening it with the user's standard application.
File myFile = new File("F:/test.pdf");
Desktop.getDesktop().open(myFile);
My standard application for pdf files is for example Adobe Reader - so Adobe Reader opens up and displays the file. - So far so good.
Is there any way to delete this "test.pdf" after I close the file/my Adobe Reader?
Check the following link:
Java: Check if file is already open
Run an infinite loop after you open the loop, as mentioned in the above thread, verify and close the file accordingly.
Thanks,
JK
You can create the file in the temp directory, so you will not have to worry about removing it.
To create a file in the temp directory you should use the File.createTempFile method.

Parsing xml files in android

I am developing an android app using code from a normal java application.
In this java application i am parsing an XML file which i get like this:
File xmlFile = new File("../project/src/resources/words.xml");
Now in android this doesn't seem to work. I get a file not found exception.
I tried to save the file in the res/xml directory but I'm not sure how to get to it.
Can i use the same code to parse the XML as I used for my java application or is there a special way to parse XML files in android?
What is ../project/src/resources.words.xml? Is that a pathname in your project directory on your development machine? Of course an Android program is not going to have access to file paths defined on your machine.
If words.xml is a static file that you'd like access to, you should include it in the /res/raw subdirectory of your project. Then you can access it using the methods described in the documentation here:
http://developer.android.com/reference/android/content/res/Resources.html#openRawResource(int)
Or, you can put it in /assets and use this method:
http://developer.android.com/reference/android/content/res/AssetManager.html
You can do:
InputStream is = this.getResources().openRawResource(resourceId);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
... then read the content of the file as a stream ...
Your file must be placed in res/raw/yourfile and resourceId is an integer in R.raw... corresponding to your filename (R.raw.yourfile)

Categories

Resources