Results 1 to 3 of 3
  1. #1
    asifzbaig is offline Member
    Join Date
    May 2011
    Rep Power

    Default :( Text File Opening Problem

    I am just got trapped in a very bad situation,

    Trying to open a text file and shows the text into a jTextPane... But problem is that when i am trying to open that file with a File object it gives an error of path not found,

    I had tried two ways to open it :
    Java Code:
    File f = new File("/FileFolder/file.txt");
    here the dicrectory "FileFolder" is different from the folder in which the Class is created (whose name is "Classes"), but both the folders are in same Source folder "src" in my NetBeans Project Folder.
    It shows me error that Specified path is not found

    The second way i am trying is :
    Java Code:
    File f = new File(getClass().getResource("file.txt").getFile());
    I have tried this way by copy the file.txt into that same folder in which my class is exist that is, Classes folder..

    But her also a strange error occurs and message shows that :
    The system cannot find the path specified.

    Actualy it tries to open the path :


    I know this is wrong, but i am unable to understand that WHY IT OPENS THE "CLASSES" FOLDER TWO TIMES???? Actually that correct path must be like:


    Please help me out from this........


  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    What happens if you take the program outside of the IDE and try to execute it in a command prompt window?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Typical case of using an IDE without taking time to learn the basics. Open Windows Explorer and examine the structure Netbeans creates subordinate to the project folder.

    You have to Build the project before resources get copied from the source tree to the build tree.


Similar Threads

  1. age old problem - best way to check if file is text
    By madroadbiker in forum Advanced Java
    Replies: 11
    Last Post: 05-27-2011, 06:57 PM
  2. writing to text file problem
    By blumdiggity in forum Networking
    Replies: 1
    Last Post: 02-26-2010, 02:43 PM
  3. Focus on Text at the opening of shell
    By antogrim2 in forum SWT / JFace
    Replies: 0
    Last Post: 10-14-2009, 10:09 PM
  4. Opening Text Files with Default System Editor
    By Pesch in forum Advanced Java
    Replies: 5
    Last Post: 10-08-2008, 06:17 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 01:55 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