Results 1 to 2 of 2
- 08-08-2009, 05:05 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 32
- Rep Power
- 0
Load file in GUI instead of notepad
In my program you can do: file->open file
you have to enter a name, and gedit (on linux) or notepad (on windows) loads the file,
is it possible to load the content of a file in a textbox?
current code
PS: WelcomeText is a textboxJava Code:logdialtext = "What is the name of the file? \n(it should be located in D_MENU/files)"; textname = WelcomeMsg.showInputDialog(logdialtext); WelcomeText.setText("Opening " + textname); String editor = "gedit"; File file = new File("/home/darragh/Documenten/D_MENU/files/" + textname); boolean exist = file.exists(); if(exist) { try { Runtime.getRuntime().exec(editor + " " + file); WelcomeText.setText(textname + " Opened succesfull"); } catch (IOException ee) { WelcomeText.setText(textname + " could not been opened"); } } else { WelcomeText.setText(textname + " doesn't exist"); }
- 08-08-2009, 05:57 PM #2
Member
- Join Date
- Aug 2009
- Posts
- 32
- Rep Power
- 0
I found the solution on my own:
Java Code:Scanner s = null; try { s = new Scanner(new BufferedReader(new FileReader("/home/darragh/Documenten/D_MENU/files/" + textname))); while (s.hasNext()) { WelcomeText.append("\n"); WelcomeText.append(s.next()); } } catch (IOException ex) { WelcomeText.setText("Couldn't open " + textname); } finally { if (s != null) { s.close(); } }
Similar Threads
-
load xml file in servlet help please
By khdani in forum Java ServletReplies: 2Last Post: 10-05-2009, 10:28 PM -
Load file to data structure
By TinoJF in forum New To JavaReplies: 4Last Post: 03-31-2009, 03:16 PM -
Not able to load a properties file
By Happy9959 in forum New To JavaReplies: 12Last Post: 07-29-2008, 07:15 AM -
How to Save/Load Vector to/from file
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:37 PM -
how to load a file in remote machine
By christina in forum New To JavaReplies: 1Last Post: 08-06-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks