Results 1 to 3 of 3
  1. #1
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

    Default text editor does not open file

    My program compiles and runs. But when I try to open a file it does open it
    This is the code responsible for opening a file.
    Java Code:
    private void openFile()
    		{
          
             try
             {
                FileDialog f=new FileDialog(this,"OPEN",FileDialog.LOAD);
                f.show();
                fname=f.getFile();
                dir=f.getDirectory();
                if(fname==null||dir==null){}
                else
                {
                   filename=fname;
                   directory=dir;
                   File fi=new File(directory,filename);
                   FileInputStream fs=new FileInputStream(fi);
                   byte b[]=new byte[fs.available()];
                   fs.read(b);
                   txtArea.setText(new String(b));
                   txtArea.append("");
                   setTitle(filename+" - NOTEPAD");
                   txtArea.setCaretPosition(0);
                }
             }
                catch(IOException e)
                {
                   JOptionPane.showMessageDialog(this,"File is not found.Please verify the file name","OPEN",JOptionPane.WARNING_MESSAGE);
                   Open.doClick();
                }
          
                }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by globo View Post
    My program compiles and runs. But when I try to open a file it does open it
    This is the code responsible for opening a file.
    Print the text you have just read and see what you got.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    globo is offline Member
    Join Date
    Sep 2010
    Posts
    61
    Rep Power
    0

Similar Threads

  1. How correctly open text file?
    By artemff in forum CLDC and MIDP
    Replies: 3
    Last Post: 12-23-2009, 06:39 PM
  2. Help for a Text Editor.
    By necroninja in forum Advanced Java
    Replies: 0
    Last Post: 08-01-2009, 05:21 PM
  3. SWT Text Editor Demo
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:35 PM
  4. SWT Text Editor
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-07-2008, 04:43 PM
  5. Problem in Text Editor
    By mustahsan4u in forum New To Java
    Replies: 2
    Last Post: 03-26-2008, 02:34 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
  •