Dropdown Menu Opening Bat File - java

I need some help.I have a Java program with a drop-down menu,there is an option in that menu to launch a test.bat file, what code would I use to specify the system path for it to open test.bat? Test.bat is an external file for testing purposes.
EDIT
This problem has been resolved.

File f = new File("test.bat");
Desktop.getDesktop().open(f);

Related

How to open .txt using windows explorer context menu in java swing?

I am making a text editor for .html, .CSS, .js, .txt etc.
First I made my software in java swing and then I changed it to jar file then I changed it to exe file using launch4j and then I made it setup using innosetup but if I install this software and I right click on a file in windows explorer and choose open with and then I select my software and open it, it just open my software not the selected file so how to do it?
Windows will supply the path to the file as args[0] in your main method.
if(args.length > 0) {
Path txt = Path.of(args[0]);
//code to handle
}

How To Open Files With .Jar (Java) Application?

Tough question here. How do you open a file in java, in the way that when you double click on the file it automatically opens in a java application.
I'm making a musicplayer (first real big Java project for me) and I have no clue how to acheive this. When you open, lets say, a .mp3 file it will open in whatever default program you have selected for it (such as VLC mediaplayer or Windows Media Player). What I want is to be able to set the .jar file of my application as the default program for .mp3 files, and then to be able to actually launch the files in the application.
When I currently try to open a file with the application I get a windows error saying "This app cannot be executed on your pc". But when I launch the .jar itself without doing it by trying to open a .mp3 file it runs just fine.
Does anyone know how to acheive what I want? Many thanks in advance!
---edit---
I do not mean that you can select a default program for the mp3 file. The problem is that windows throws the error shown above, and that I dont know how to handle the application being launched by opening a file (which does not ope due to the error).
I think the problem is that you have to open a file with a .exe , so you sshould use an exe wrapper (I use jsmooth: download here)
BUT, before you do that, you need to accept that info. So in the main class, the "args" is a list of info about how it's being launched. If you are opening a file, the array's first argument will be the opened file's destination. SO I would accept it like this:
if (args.length > 0) {
File f = new File(args[0]);
start_the_application_with_a_file(f);
} else {
start_the_application_without_a_file();
}
C:\ProgramData\Oracle\Java\javapath\java.exe -jar "C:\Program Files\YourApp.jar" %* within a batch-file (.cmd) might do it.

Added text file in eclipse but cannot find it

I have a java project in eclipse. I right clicked my package and used the option: "add -> new textfile" a textfile was created but I cannot see it in my package.
Where do I located the textfile I created?
If you used New->General->Untitled Text File (I'm using Luna) the file appears in the text editor but isn't saved to the filesystem until you explicitly save it, and then you are prompted for the location to save it to.
You need to save the file as File -> Save or File -> Save As to locate it in package / directory.
right click on you package New>Other>General>Untitled Text File

Changing java security file in windows

I am trying to edit the java.security file in windows. When I add an entry to it and try to save, it says 'Access Denied'. How do I change the permissions to this file.
I have also tried by making notepad to Run as administrator but it didn't work.
Please help.
Try this and say if it works. It worked for me while opening hosts file.
http://www.labnol.org/software/edit-hosts-files-as-administrator/13673/
edit:
The relevant information from the linked page:
Step 1. Open your Windows start menu, search for the notepad application and then right click the notepad icon.
Step 2. Choose “Run as administrator” and then, while inside notepad, browse to folder (java.home\lib\security\java.security).
You can now edit and save that file in the same folder without any issues. To recap, the trick is that instead of directly opening a protected file in the associated application, you run the application first as an administrator and then open the file inside it.
1) Copy original java.security file to desktop.
2) Edit the file there and save it.
3) Copy the file to %JAVA_HOME%/\jre\lib\security
4) Replace the original file with modified one.

Save a file with the option to open it

I am looking for a solution to save a file in a Java (Eclipse RCP) application with the option to open the file right after saving it. Similar is when a browser saves a dowloaded file it allowes to open it. A simple FileDialog has no such option.
I think, you need to open the file yourself after you save it.
Do the following (in windows):
String cmd = "cmd.exe /c start ";
String file = "path\version.txt"; //TODO: your file path here
Runtime.getRuntime().exec(cmd + file);
Similar approach can be applied for linux environment. Search for it yourself.
If you need the option (may be a checkbox) in JFileChooser, you can extend JFileChooser and add your features.

Categories