Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Webuser

Thread: Read and Open *.txt Files? help!!

  1. #1
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default Read and Open *.txt Files? help!!

    hi guys! I have been searching through the forum but haven't found the simplest explanation on how to open a file so the user can see how the texts were saved.

    can anyone please, kindly help me? any ideas?

    Java Code:
    Example:
    
    Step 1: I created a file named "SavedHere.txt";
    Step 2: The user then writes anything, for example, a paragraph,
                     with indents and all that stuff.
    Step 3: [COLOR="DarkRed"]here's my problem.[/COLOR]
               [COLOR="Black"]the user then clicks a button labeled "view         file"[/COLOR].
    
    **I just want to know how to open a file for the user to see his input**
    Thanks a lot in advance!:)

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    can try
    BufferedReader in = new BufferedReader(new FileReader(File));
    in.readline() or other read methods

  3. #3
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default

    thanks! that worked!

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default

    Hi Eranga.. I just want to open the file.. like popping up somewhere..

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    to open with you app you can use JFileChooser to get an absolute path and then read the file and place its test to a JTextArea
    rustam likes this.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    to open with you app you can use JFileChooser to get an absolute path and then read the file and place its test to a JTextArea
    ashton, this is the way you have to work out.

    Without open the file you can simply read the file content into a stream and place it on the JTextArea. But if I'm correct you cannot do this, because sometime users are need to edit the text file too, right?

  8. #8
    kostinio is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    If i want the user to click in a button and then to open a specific file how i can do it? I don't want to do it with file chooser beause the file is specific..

    :)

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes you can do that. Did you read about the Process class? It's what all you want.

    Say you've a text file name test.txt on C:\ drive. What happen if you type the complete path on Run command (on windows)? OS identified the relevant application and pass the variable to it. Same thing you can do in Process class.

    Just go through the following code segment.

    Java Code:
    public static void main(String[] args) {
            String fileName = "c:\\test.txt";
            String[] commands = {"cmd", "/c", fileName};
            Runtime.getRuntime().exec(commands);
        }

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Open xls file in read-write mode
    By rdhaware in forum Advanced Java
    Replies: 1
    Last Post: 02-03-2009, 09:12 AM
  2. Data files - how to read random line?
    By Exhonour in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 09:28 PM
  3. Saved files are coming back as read-only
    By Manoeuvre in forum Eclipse
    Replies: 0
    Last Post: 11-21-2008, 06:18 PM
  4. [SOLVED] Read/write files using applets
    By coolFrenzi in forum Advanced Java
    Replies: 3
    Last Post: 11-17-2008, 11:45 PM
  5. Replies: 5
    Last Post: 10-17-2008, 03:13 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
  •