1

I am trying to read the contents of a text file and write to another file. The thing is I want to read the file every 1sec. Here is what I have tried.

void setData() {
      System.out.println("inside setdata");
      String line = null;
      String file = "E:/sss.txt";
      FileInputStream fis = null;
      String text = null;
      try{
             ....

     while(true) {

       byte bt[] = new byte[(int) file.length()];

        fis.read(bt);
        text = new String(bt);
        System.out.println( text);
        fis.close();  
        line = text + line;
        while(text != null) {
        Thread.sleep(2000);
        System.out.println(line);
        }     
      }
     }catch (Exception e){

            }

    }

Where am I wrong here?

What Iget is

inside setdata
inside try
http://www.
http://www.null
http://www.null
http://www.null

going on and on Thanks in advance

sahana
  • 43
  • 1
  • 2
  • 7

1 Answers1

0

You might have more luck using my async DataFetcher class:

http://tus.svn.sourceforge.net/viewvc/tus/tjacobs/io/DataFetcher.java?view=log

get the file input stream, feed that to a DataFetcher, run it in a thread, and add a FetcherListener to the DataFetcher

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80