Results 1 to 3 of 3
  1. #1
    nick2price is offline Member
    Join Date
    May 2008
    Posts
    27
    Rep Power
    0

    Default loading a text file

    I am trying to load a text file which would look somthing like
    John
    Doe
    Mr

    Each line i am trying to get assigned to a particular variable, so John should be assigned to firstName.
    I have started like
    Java Code:
    try {
    				
    				System.out.println("Please enter the name of the student file" );
    				String fileName = input.next();
    				in = new BufferedReader(new FileReader(fileName+".txt"));
    				
    				firstName = in.readLine();
    			}
    i know i will have to put it in a loop. But is there anyway i can say what line goes to what variable e.g
    firstName = in.readLine(1);
    lastName = in.readLine(2);
    title = in.readLine(3);

  2. #2
    PatoDB is offline Member
    Join Date
    Dec 2008
    Posts
    14
    Rep Power
    0

    Default

    Maybe you can try with a switch asking for the number of line that its been reading at the moment?
    ..:: abretumundo.wordpress.com ::..

  3. #3
    kosok is offline Member
    Join Date
    Dec 2008
    Posts
    4
    Rep Power
    0

    Default

    Something that's worked for me is the String split method using the new line character "\n" as my deliminator. But this was in a JTextArea, so it might not work.

Similar Threads

  1. Help loading a Binary Tree from file
    By ExplosiveWeasel in forum Java 2D
    Replies: 16
    Last Post: 12-17-2008, 02:34 AM
  2. Replies: 2
    Last Post: 12-03-2008, 12:14 PM
  3. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 05:04 PM
  4. Loading of JSP file failed
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-06-2007, 02:15 AM

Posting Permissions

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