• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Pause / Sleep in Java

Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


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){

//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) );
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic