I am making a qt application which allows the user to select a file and then upon clicking ok, start the associated program with the file already loaded. The program I want to start is java based, and I know how to use QProcess to get it to open, I don't know however how to add the file extension which the user is selecting. Any suggestions?
Did you try QDesktopServices::openUrl() ?
You can pass your program path and name as an Url (file:///) and it will be openned with a suitable application.
Sorry for leaving everyone hanging on this one, I actually solved this issue myself. Basically I just used QFileDialog to select my file I wanted to open and created a QString which was the entire command line I needed to use to get my application to run properly, which I opened via QProcess. Thanks for the help anyways.
Related
my program on startup will:
1. search for a file
2. read the file
3. and set a string to the files contents
But the way ive done it it will only work if they have the exact path that i am hard coding in.
i want the path to adapt to other computers. I think i should use the Path class but ive just heard about that so not sure where to go.
basically i want it to search for a file on any users desktop, and if its not there make it.
if you need some code to clarify i can post it just let me know
I could think of two options.
You can simply specify a file name such as "myFile.txt", so the program will search this file in its program/project folder.
If it does not exist you can write the code to create it in the program folder, instead of hard coding any absolute path.
Else, you can try using the javax.swing.JFileChooser class to pop up an Open and Save dialog box.
This will give the end-user the freedom to select any file for reading and writing.
I found below two articles with some example on how to use the class. Please refer them for more information.
https://www.codejava.net/java-se/swing/show-save-file-dialog-using-jfilechooser
How to "Open" and "Save" using java
Thanks.
You can use the path "./yourfile.txt". It will search for "yourfile.txt" in the directory ".". That means the project's current directory. Maybe it can help you.
I have developed my java application and deployed it.
I want it to detect when i double click a music file eg .mp4, .mp3 and others to open play.
I have already set it as my default but it just opens the app, it cannot pick the path of the file.
Colleagues, how do I get that file path and use it when it is called?
Thanks a lot.
I have java class file (server.class) I want to run this file to client machine using php.
My approach
download the file from server to client machine
run this file in client machine
close the cmd and delete the file after on pressing another button
tell me my approach is right or I am making it more complex.If it is complex the then suggest me what is the right approach?
You cannot run programs on a client's machine. You can provide a download link and instructions on how to run it.
If you want to avoid the client having to click a download button, all I can think of is implementing server.class as an applet inside a web page or maybe using webstart, but I don't know much about webstart, and either way the client will go through a process of agreeing to run the java code.
Also, it sounds like some shady, shady stuff you're attempting to do. I hope you're not trying to run something on a person's computer without them knowing. If that is the case... I WILL find you :P
I want to know if there is a way of opening mp3 files using either Windows Media Player and VLC Media Player.
I have the path of the file saved as a String and was wondering if I can use this to open the file on either of the applications mentioned above.
I understand one method of doing this is by using the Desktop class but this opens the file using the default application, which is Windows Media Player in my case. How would I open the file in VLC media player?
try
Runtime.getRuntime().exec("<your vlc path> <your file>");
I.E.
Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\VideoLAN\VLC\\vlc.exe\" abc.mp3");
Tried and it works
Judging by the Desktop.open apidoc and
Desktop tutorial it looks like the open method can only open the file in their default associated program.
So, you have (maybe) two options here:
access the registry and change the default association (not a nice one)
might try giving a URI and opening it via browser, which might result in opening the file in desired program. However, it looks like the file scheme is the only acceptable solution, and that will most probably open in the default program. There is a mms scheme but it is used for video-streaming, and again, it will most probably open in the default program.
Here is a link to the Runtime.exec solution for windows, linux and osx variant.
You should know the path to the VLC and/or WMP. Then you can use Runtime class for this.
Process p = Runtime.getRuntime().exec("c:/vlc/vlc.exe " + mp3FileName);
i am checking the text file which is present in the mapped hard drive or not.
File cfile = new File("R:\\Link Fixer Reports\\ServiceTest.txt");
but it shows that file is not present
when use c:\\t.txt
it shows the file
what is the problem and how can i rectify the problem?
It's likely that the user that your code is running as can't see the mapped directory.
You've tagged this question as java-ee so I'd guess that this code is running within a web service or similar? What user is your application server running as? Verify that this user can access the location. As #Christian pointed out, a UNC-Path is a better way to go - just make sure that you can access the network location. Try runas net use to double-check.