Results 1 to 2 of 2
  1. #1
    Kruptein is offline Member
    Join Date
    Aug 2009
    Posts
    32
    Rep Power
    0

    Default 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
    Java 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");
            }
    PS: WelcomeText is a textbox

  2. #2
    Kruptein is offline Member
    Join Date
    Aug 2009
    Posts
    32
    Rep Power
    0

    Default

    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

  1. load xml file in servlet help please
    By khdani in forum Java Servlet
    Replies: 2
    Last Post: 10-05-2009, 11:28 PM
  2. Load file to data structure
    By TinoJF in forum New To Java
    Replies: 4
    Last Post: 03-31-2009, 04:16 PM
  3. Not able to load a properties file
    By Happy9959 in forum New To Java
    Replies: 12
    Last Post: 07-29-2008, 08:15 AM
  4. How to Save/Load Vector to/from file
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:37 PM
  5. how to load a file in remote machine
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •