Results 1 to 9 of 9
- 03-13-2010, 01:16 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
Opening any file of "specified extension" by a Java application
Java Code:import java.io.File; import java.io.FileNotFoundException; import java.util.*; public class Main { private Scanner input; public void openFile() { try { [COLOR="Red"]input = new Scanner(new File("test.sk"));[/COLOR] javax.swing.JOptionPane.showMessageDialog(null, input.next()); } catch (FileNotFoundException fe) { System.err.println("Error opening file"); System.exit(1); } } public void closeFile() { if (input != null) { input.close(); } } public static void main(String[] args) { Main m = new Main(); m.openFile(); m.closeFile(); } }
Hey guys I created a file of extension ".sk" containing some text.... now i created an installer of the application i created above using "Advanced Installer" then i right clicked the same file from my drive and opened it with the application installed ... I got open:cool:... but now i want to open any file of the same extension ..just by right clicking or by associating the application to this file extension ... but i don't know how to specify any file of the same extension in the above code in red..
plz suggest. thanx
-
Unless I'm misinterpreting your goals, I think that you have to futz with operating system settings to achieve this.
- 03-13-2010, 01:34 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
I can't use
input = new Scanner(new File("*.sk"));
instead of
input = new Scanner(new File("test.sk"))
Isn't there any possible way to achieve this??
-
If I understand you correctly, you want to double click or right click on an .sk file and have it run using your program. Is this correct?
If so, then perhaps you can configure the OS to call your program whenever an .sk file is double clicked, and have the OS pass the file's name into your program's command line. Then the program has to be configured to accept the file from the command line and use it correctly, and also throw an error and exit if the file passed is not a valid .sk file. Would this work for you?
- 03-13-2010, 01:53 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
How would I do that .. plz.explain.have the OS pass the file's name into your program's command line
-
-
For instance, if it is a Windows environment, I think what you need to do is go into windows explorer, right click on a .sk file, any .sk file, click Open With, and change the default program that should open this file. I have no idea how to do this with other OS's.
- 03-13-2010, 02:13 PM #8
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
[solved]
Java Code:import java.io.File; import java.io.FileNotFoundException; import java.util.*; public class Main { private Scanner input; public static String str = ""; public void openFile() { try { input = new Scanner(new File(str)); javax.swing.JOptionPane.showMessageDialog(null, input.next()); } catch (FileNotFoundException fe) { System.err.println("Error opening file"); System.exit(1); } } public void closeFile() { if (input != null) { input.close(); } } public static void main(String[] args) { Main m = new Main(); str = args[0]; m.openFile(); m.closeFile(); } }
YOu are absolutely right. It worked!! thnx buddy. I would for sure look for other OS's ..thnx.
By the way .. can you help me solving my last post-
Unable to render printing the complete JPanelthese are still unresolved!plz.gov.sns.tools.math.ElementaryFunction
-
You're quite welcome.
I wish I could, but you'll need more of a graphics wiz like Rob Camick or Darryl to help you solve that one. Did you post a decent SSCCE in that thread? If not, doing so will increase your chances of getting decent help fast. Best of luck!By the way .. can you help me solving my last post-
these are still unresolved!plz.
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
Dr Java compiler error "This application requires a Java Runtime Environment 1.5.0"
By applewood13 in forum New To JavaReplies: 8Last Post: 12-30-2009, 11:40 AM -
Java "application infrastructure"
By id_powell in forum New To JavaReplies: 1Last Post: 12-22-2009, 12:46 PM -
[SOLVED] Eclipse-Run As "Java application" missing!!
By Triji in forum EclipseReplies: 5Last Post: 01-27-2009, 03:49 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks