1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Read File By Line

Discussion in 'Java' started by rendra_mm2, Oct 26, 2009.

  1. rendra_mm2

    rendra_mm2 New Member

    Joined:
    Jul 10, 2009
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Freelancer
    Home Page:
    Hey advance,,, please help ...
    i wanna read a txt file by line, and get the different value

    example :
    file.txt
    you and me
    me and you
    you and me

    with 3 lines in that file, i want get the value just you and me and me and you

    please ... :disappoin
     
  2. SyferZookie

    SyferZookie New Member

    Joined:
    Nov 6, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    College Student , taking up IT
    Location:
    Philippines
    here's the codes you needed just edit it for your self
    and i know that it will help you and you can do it after i post it
    Code:
     FileWriter key = new FileWriter("File");
      BufferedWriter kbd = new BufferedWriter(key);
      BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Input: ");
      String input = k.readLine();
      
      kbd.write(input);
      kbd.close();
      
      //kbd.write("The");
      //kbd.write(" Zombie");
      //kbd.write(" Is there");
      //kbd.write(" NOW");
     
    
    
    i almost forgot
    this are to write
    just change the write to read
    if u want that ur prog will read the txt file that u made.

    btw,
    thank me if i helped you
    if not its up to you :P
     
  3. devunion

    devunion New Member

    Joined:
    Sep 26, 2008
    Messages:
    19
    Likes Received:
    2
    Trophy Points:
    0
    Take it!

    Code:
    public class Reader {
        public static void main(String[] args) {
            try {
                BufferedReader br = new BufferedReader(new FileReader("file.txt"));
    
                List uniqueLines = new ArrayList(); 
                String line;
                while ((line = br.readLine()) != null) {
                    if (!uniqueLines.contains(line)) {
                        uniqueLines.add(line);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
     
    Last edited by a moderator: Nov 8, 2009
    shabbir likes this.
  4. SyferZookie

    SyferZookie New Member

    Joined:
    Nov 6, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    College Student , taking up IT
    Location:
    Philippines
    LOL! your codes are more complicated than my post :D
     

Share This Page