File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Pause / Sleep in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pause / Sleep in Java" Watch "Pause / Sleep in Java" New topic

Pause / Sleep in Java

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91

In the following Code: I am trying to configure a sleep or wait , Can anyone give me some HINT on how to do this ?



public class ReadFile {

* Fetch the entire contents of a text file, and return it in a String.
* This style of implementation does not throw Exceptions to the caller.
* @param aFile is a file which already exists and can be read.
static public String getContents(File aFile) {
//...checks on aFile are elided
StringBuffer contents = new StringBuffer();

//declared here only to make visible to finally clause
BufferedReader input = null;
try {
//use buffering
//this implementation reads one line at a time
input = new BufferedReader( new FileReader(aFile) );
String line = null; //not declared within while loop
while (( line = input.readLine()) != null){

//Trying to implement a configurable wait here

catch (FileNotFoundException ex) {
catch (IOException ex){
finally {
try {
if (input!= null) {
//flush and close both "input" and its underlying FileReader
catch (IOException ex) {
return contents.toString();

public static void main ( String[] aArguments ) throws IOException {
File testFile = new File("checkpoint_20000_.txt");

System.out.println( "File contents: " + getContents(testFile) );
marc weber

Joined: Aug 31, 2004
Posts: 11343

Just call the static method Thread.sleep(long millis). This method throws an InterruptedException, so you'll want to enclose it in a try/catch block.

See API...
[ February 18, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
subject: Pause / Sleep in Java
Similar Threads
Read from file and display nonduplicate words in ascending order.
filenotfound Exception encountered,kindly help
Pls HELP! How to count the number of row in file?
Reading & Writing to text file using ArrayList incorrectly
problem in rediredtin GUI to IO Streams