The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: GOing from VB to Java

Wait, I'm confused. Are you trying to open the file in a text box (ie: part of the GUI) or are you trying to get the file to open up in its default editor (ie: opening the document in MS Word or something)?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: GOing from VB to Java

The JVM can not run other programs directly, its a virtual machine and this is part of its build in malware security.
There is however the exec() method in the Runtime class which can be used to deliver command line commands to the OS.
You can potentially use that to have the OS open a text document but there is no guarantee that it will actually work on all operating systems.

There is also the ProcessBuilder class which might also work to get things done, but I never used it and cant quite tell you anything about it.

Re: GOing from VB to Java

Try:

java.awt.Desktop.getDesktop().edit(file);

I'm told there might be issues with earlier versions of Windows (XP and 2003) while using this. file would be a File (File (Java Platform SE 7 )) object, which you can create from the path of the file the user requested.

@Cornix: While you are mostly correct, Java does support some ways of accessing system resources. Most commonly, these resources can be accessed through classes like System and Desktop (I don't know of any class specifically dedicated to accessing system resources, these can just be used as work-arounds). Consider the fact that if the JVM couldn't access any system resources, printing would be impossible (but you can print from Java).

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: GOing from VB to Java

To reiterate what Norm said, you need to create a File object (look at my previous post for a link to the API document for the File class).
What does txtInput.getText() represent? Is it a file path or something?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: GOing from VB to Java

So the user selects a file and the file and path get put into the the text box called "txtInput". I want the user to be able to click a button that will open that file in a text editor. I will look at the APC.

Re: GOing from VB to Java

(there are obviously other things you should do, like checking input, but this is how you create a new file and use the method)

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/