I want to implement the following Task
1) Read till end of file
2) In each Line of the file there is a time mentioned. You need no call a method( code of which I have already written)
3)Wait for the time mentioned in that line of file and then again read the next line of file

I want to implement this code. It will start when I press a start button and can be stopped in the middle if I press a stop button

Also this time delay mentioned mentioned in the file is approximately 70 ms. I want to avoid using Thread.sleep() in an infinite loop

Is there way a to use Timer class to implement the above code.

I would have used the sleep method:

// line read:
line = readLine();

// take the time at the end of the line:
lone time = ... ;

try {
  Thread.sleep(time);
} catch (Exception e) {
}

// repeat the loop

I would suggest to put the above in a Thread class and start it. When the "stop" button is clicked, you can call the sleep method on the above thread.
Actually I don't know if you can do that, but if you check the API you will find a method that will cause your thread to wait. Maybe the 'wait' method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.