Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Re: Reading a file line by line using the Scanner class

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: Reading a file line by line using the Scanner class

    I want to store all the lines in a file to compare them with the input. So please tell me how can i store all the lines of the file. My file contains username and password. I want to authenticate an user by comparing them with the data in the file...........


  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How to store all lines of a file

            	String data;
            	FileInputStream in=new FileInputStream("D:\\Shared\\abc.txt");
            	BufferedReader bw=new BufferedReader(new InputStreamReader(in));
            	while((data=bw.readLine())!=null)
            	{
            	System.out.println(data);
            	String datar[]=data.split(",");
     
                 for(int k=0;k<1;k++)
                 {
             		String ate=(String) datar[k];
             		System.out.println(ate);
             		for(int j=1;j<2;j++)
             		{
             			String a=(String) datar[j];
             			System.out.println(a);
            	    }
                 }
     
            	}

    I want to authenticate the user by reading data from file. my file contains username and password. i am not able to store all the lines of a file. If i am able to store all lines somewhere i can compare them with the input user has entered........
    Thanks in advance.....
    Last edited by Freaky Chris; May 8th, 2013 at 02:59 AM. Reason: Update code tags so they are correct

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: How to store all lines of a file

    Why not just create an ArrayList for example and pop each line into that,

    ArrayList<String> myArrayList = new ArrayList<String>();
    ...
    while( (data=bw.readLine()) != null) {
        myArrayList.add( data );
    ...


    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to store all lines of a file

    Thanks...
    thank you so much.........

Similar Threads

  1. [SOLVED] reading a file line by line
    By shenaz in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 20th, 2013, 12:10 PM
  2. Replies: 10
    Last Post: September 16th, 2011, 08:49 PM
  3. Trouble Reading Line in File
    By Mandraix in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 4th, 2011, 11:47 PM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 08:34 AM
  5. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 08:34 AM

Tags for this Thread