Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Read File By Line (http://www.go4expert.com/forums/read-file-line-t19895/)

rendra_mm2 26Oct2009 14:19

Read File By Line
 
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

SyferZookie 6Nov2009 07:17

Re: Read File By Line
 
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

devunion 8Nov2009 16:53

Re: Read File By Line
 
Take it!

Code: Java

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();
        }
    }
}


SyferZookie 11Nov2009 09:33

Re: Read File By Line
 
LOL! your codes are more complicated than my post :D


All times are GMT +5.5. The time now is 13:05.