File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Pause / Sleep in Java

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
Hi,

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

Thanks,

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

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){
contents.append(line);

//Trying to implement a configurable wait here

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

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

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

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...
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html
[ 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
sscce.org
 
 
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