How to delay output in Java

Hi,
I have the following code in my program:
output.println (" This is a test " ) ;
When I run the program, the string, "This is a test", will be displayed on the screen at one time. However what I want is that the first char "T" is displayed first and then after, let say, 1 sec, the second char "h" is displayed and so on.
Could you please advise how this can be done?
Thank you very much for your help.
Best regards,
Jackie

Could you please advise how this can be done?Sure, simply build a, say, LazyBonesOutputStream:public class LazyBonesOutputStream {
   private OutputStream sink;
   private int millis;
   public LazyBonesOutputStream(OutputStream sink, int millis) {
      this.sink= sink;
      this.millis= millis;
   public void write(int b) throws IOException {
      try {
         Thread.sleep(millis);
      catch (InterruptedException ie) { /* muffle */ }
      sink.write(b);
}wrap this one up in a PrintStream and use System.out as its sink.
kind regards,
Jos

Similar Messages

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • How can I output text in a browser window in JAVA?

    How can I output text in a browser window in JAVA?

    "response.getWriter().print()" is the most common method when using servlets

  • How to print "Text" in JAVA(TM)....

    Does anyone know how to print "text" using Java?
    - Here's an example output...
    NOTE: # == 'empty spaces'
    --------------------------- <- Paper
    |###################|
    |####Welcome#########|
    |###################|
    |########to##########|
    |###########JAVA(TM)##|
    |###################|
    |#######Programming####|
    |###################|
    Please post a complete << SAMPLE CODE >> for printing the "text" (Welcome to JAVA(TM) Programming. Including the indentions. So it will not be like this...
    -------------------- <- Paper
    |Welcome |
    |to |
    |JAVA(TM) |
    |Programming |
    | |
    | |
    | |
    | |
    Thanks.

    Please read How To Ask Questions The Smart Way

  • How can i  apply this  java program for  a jsp page?

    import java.io.*;
    import java.util.*;
    public class FileProcessing
      //create a vector container  for the input variables
         Vector variables = new Vector();
      //create a vector container for the constants
         Vector constants = new Vector();
      /*create a string expression container for the equation
         as read from the file */
         String expression = " ";
      //create double result container for the final result
         double result = 0;
         public boolean processFile(String filename,String delim)
          //index for values vector
              int num_values = 0;
          //index for constants vector
              int num_constants = 0;
          //current line being read from the external file.
              String curline = " ";
          //start reading from the external file
              try
                   FileReader fr = new FileReader(filename);
                   BufferedReader br = new BufferedReader(fr);
                   while(true)
                        curline = br.readLine();
                        if(curline == null)
                             break;
                    //determine the type of current interaction
                        boolean variable = curline.startsWith("input");
                        boolean constant = curline.startsWith("constant");
                        boolean equation = curline.startsWith("equation");
                        boolean output = curline.startsWith("result");
                   //on input variables
                        if(variable)
                          StringTokenizer st = new StringTokenizer(curline,delim);
                          int num = st.countTokens();
                          int count=0;
                          while(st.hasMoreTokens())
                               String temp = st.nextToken();
                               if(count==1)
                                    byte b[]= new byte[100];
                                    System.out.println(temp);
                                    System.in.read(b);
                                    String inputval = (new String(b)).trim();
                                    variables.add(num_values,inputval);
                                    num_values++;
                               count++;
                        // on constant values
                        if(constant)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==1)
                                       byte b[]= new byte[100];
                                       System.out.println(temp);
                                       System.in.read(b);
                                       String cons = (new String(b)).trim();
                                       constants.add(num_constants,cons);
                                       num_constants++;
                                  count++;
                        // on equation
                        if(equation)
                             StringTokenizer st = new StringTokenizer(curline,delim);
                             int num = st.countTokens();
                             int count = 0;
                             while(st.hasMoreTokens())
                                  String temp = st.nextToken();
                                  if(count==2)
                                       this.expression = temp;
                                  count++;
              // now we are ready to evaluate the expression
                       if(output)
                          org.nfunk.jep.JEP  myparser= new org.nfunk.jep.JEP();
                          myparser.setAllowAssignment(true);
                          for(int i=1;i<variables.size()+1;i++)
                             String name = "arg"+Integer.toString(i);
                             myparser.addVariable(name,new Double(variables.get(i-1)
                                                .toString()).doubleValue());
                          for(int i=1;i<constants.size()+1;i++)
                               String name = "arg" +Integer.
                                         toString(i+variables.size());
                               myparser.addConstant(name,new Double(constants.get(i-1).toString()));
                   //output is obtained as follows
                          myparser.parseExpression(expression);
                          result = myparser.getValue();
                          System.out.println("Assay value: "+result);
              catch(Exception e)
                   System.out.println(e.toString());
              return true;
         public static void main(String[] args)
              FileProcessing fp = new FileProcessing();
              fp.processFile("input.eqn",":");
    }//my text file name is: "input.eqn" (given below)
    input:Enter Value1:arg1
    input:Enter Value2:arg2
    input:Enter Value3:arg3
    constant:arg4
    constant:arg5
    Equation:arg1+arg2+arg3
    result:

    how can i apply this java program for a jsp pagewhy do you want to do this ?
    Your program reads from a file on the disk and formats based on a patterm.
    Jsp is not intended for such stuff.
    ram.

  • Is the output of java -version reliable?

    Hi,
    As part of an installer, I'm trying to write a script to check that the user's JRE is recent enough. With all JRE's I tried I noticed that the first line of output from: java -version is always of the form: java version "1.3.1" Can I rely on this to always be the case? I had a look through some of the specifications, but they are more concerned with how the JRE runs, not how you invoke it.
    Cheers,
    Gary

    I think it's best to get the system property "java.version" and to check upon the result.
    System.getProperty("java.version");

  • How to pause output in command prompt

    I have 10 sentence for instance, i want to display one sentence each time i press enter. Does anyone know how to do it in java?(command prompt)

    1. Wrap the default System.err and System.out in your own PrintStreams
    2. Replace them with your wrapper classes (see System.setErr(PrintStream) etc)
    3. In the wrapper classes, parse output looking for '\n' chars + any time you find one, write to that point, then read a return from System.in

  • How to program this in java? Please help

    How to program this in java?
    please explain steps, it has to come out like this:
    example
    input: 3b1w3b
    output:
    BBBWBBB

    import java.io.*;
    public class Test {
    static java.io.PrintStream o = java.lang.System.out;
    public static void main(String[] args)throws Exception {      
         BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Enter plot for printing: ");
         String s = BR.readLine();
         char[] cs = s.toLowerCase().toCharArray();
         for(int i=0, j=0; i < cs.length-0x1; i+=0x2, j=0)
              while(j++ < (int)(cs[i]-0x30))
                   o.print((char)(cs[i+0x1]-0x20));
    I tried changeing it to this so I can enter my own string, but I want to change it some more so that it can enter multiple input separated by space, so that it can form a sort of picture line by line. I tried using tolkenizer but I get errors. I dont know how to use tolkenizer properly can anyone please TEACH. you dont have to tell how or give me the code if you dont want to. yes I know Im a noob and I dont know java as good as everyone here, If everyone thinks I don't deserve help then DON'T help, I'm just trying to learn programming

  • Get output of java.exe within C/C++-Application

    Hello together,
    I want to call java.exe from a C-program and get
    the console output of java.exe to display in a
    MessageBox.
    How can I achieve this?
    I would be very happy if I found a solution here...
    Best regards
    Christian

    Happy, but you should be surprised. You have asked a C programming question, namely "I want to call another program from code in the C language and get its console output to display in a MessageBox". No doubt there are people who read these forums and who know C, but it wasn't the best choice.

  • Get complete output from java.lang.Process

    How do I get the complete output from java.lang.Process?
    By the time I've started reading from Process.getInputStream() the process has already terminated...

    I solved the problem:
    private int exec(String pArguments[], OutputStream pOut, OutputStream pErr) throws IOException {
         class ProcessOutputPrinter implements Runnable {
              private InputStream ivIn;
              private OutputStream ivOut;
              public ProcessOutputPrinter(InputStream pIn, OutputStream pOut) {
                   ivIn = pIn;
                   ivOut = pOut;
              public void run() {
                   try {
                        for(int tByte; (tByte = ivIn.read()) != -1; ) {
                             ivOut.write(tByte);
                        ivOut.flush();
                   catch(IOException e) {
                        e.printStackTrace();
         // Start process
         Process tProcess = Runtime.getRuntime().exec(pArguments);
         // Create out printer
         Thread tOutPrinter = new Thread(new ProcessOutputPrinter(tProcess.getInputStream(), pOut), "NamingAdmin out-printer");
         tOutPrinter.start();
         // Create err printer
         Thread tErrPrinter = new Thread(new ProcessOutputPrinter(tProcess.getErrorStream(), pErr), "NamingAdmin err-printer");
         tErrPrinter.start();
         // Wait for process and printers to finish
         try {
              tProcess.waitFor();
              tOutPrinter.join();
              tErrPrinter.join();
         catch(InterruptedException e) {
         // return process exit value
         return tProcess.exitValue();

  • How do you output n number of spaces??

    I want to output a varying number of spaces, in visual basic there is a method string(int, string). and for a space you use chr(32). How do you this in JAVA?
    So to output 28 spaces you do this:
    string(28, chr(32))

    shaunkalley11 solution is good, but it would probably be more efficient to do:
    public static void printNChars(int n, char c) {
        if (n < 0) {
            throw new IllegalArgumentException("n cannot be less than 0");
        char[] temp = new char[n];
        java.util.Arrays.fill(temp,c);
        System.out.print(temp.toString());

  • How do I include a JAVA file in my website  using DreamweaverCC ?

    Hi.  I searched the forums and it seems that all questions relating to JAVA and Dreamweaver elicit zero replies.
    I hope that someone has some direction.  Thanks again.
    I have a JAVA file that I want to include or have run within one of my pages in my WebSite.
    file > new > create > and there is not an option for JAVA but there is one for PHP etc. etc.
    How do I incorporate a java script into my Web Site ?
    I thought that I could just copy the code into the file here - at least to begin with  - but JAVA  runs in the background.
    I am lost
    conceptually
    and I do not know how to go about this task
    structurally.
    Thanks again,
    Regina

    JQuery is a core JavaScript library used by millions of web sites.  It's the "do more & write less code framework."  If you're into re-inventing the wheel every time you need an advanced feature (plugin), feel free to manually code it yourself with JavaScript.  However, you'll need to test & debug your scripts in every conceivable browser and OS before you can be sure it's viable for use on a production site.
    On the other hand, you could use a plugin and be up & running in 5 minutes or less. See the code below.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>HTML5, with Fancybox2 Viewer</title>
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <!--LATEST JQUERY CORE LIBRARY-->
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <!--FANCYBOX plugins-->
    <link href="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.4/jquery.fancybox.css" rel="stylesheet" media="screen">
    <script src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.4/jquery.fancybox.pack.js"></script>
    <style>
    body {
        background: silver;
        font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    #wrapper {
        width: 1000px; margin:0 auto;
        background:#FFF;
    /**this styles image container**/
    #thumbs p {
        float: left;
        width: 180px;
        height: 12.5em;
        margin: 10px 22px 0 22px; /**space between containers**/
        padding: 10px; /**space around containers**/
        border: 1px solid silver;
        /**rounded borders**/
        -moz-border-radius: 20px;
        -webkit-border-radius: 20px;
        border-radius: 20px;
        /**this styles caption text**/
        font: italic 14px/1.5 Geneva, Arial, Helvetica, sans-serif;
        color: #666;
        text-align: center;
    /**recommend using same size images**/
    #thumbs img {
        width: 160px; /**adjust width to thumbnail**/
        height: 120px; /**adjust height to thumbnail**/
        margin-bottom: 1.5em;
        opacity: 0.75;
    #thumbs img:hover { opacity: 1.0 }
    /**float clearing**/
    #thumbs:after {
        content: ".";
        clear: left;
        font-size: 0px;
        line-height: 0;
        display: block;
        visibility: hidden;
    </style>
    </head>
    <body>
    <div id="wrapper">
    <h1><a href="http://fancyapps.com/fancybox/">Fancybox2</a> Viewer with images</h1>
    <!--insert thumbnails with links to full size images below-->
    <div id="thumbs">
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 1" /></a> <br />
    Caption 1 </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 2" /></a> <br />
    Caption 2 </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 3" /></a> <br />
    Caption 3 </p>
    <p><a class="fancybox" data-fancybox-group="gallery" href="http://placehold.it/400x320.jpg" title="optional captions"><img src="http://placehold.it/160x120.jpg" alt="Thumbnail 4" /></a> <br />
    Caption 4 </p>
    <!--end thumbs--></div>
    <!--end wrapper--></div>
    <!--FancyBox function code-->
    <script>
    $(document).ready(function() {
        $('.fancybox').fancybox();
    </script>
    </body>
    </html>
    Nancy O.

  • Fedora 13: After upgrading from FF3.6 to FF6.0.2 I no longer have a Java plugin. How do I configure the Java Plugin for FF 6 ? There is no Java Plugin at the site

    I am Fedora 13x64 bit. I just installed FF v6.0.2 from the FF download site. I backed up the existing FF 3.6 as firefox_old
    I need to have a Java plugin to access company site, how do I configure the Java Plugin ?
    At the Plugin area in FF6 there is no Java Plugin available, even after a search.
    I have Java 1.6.0 installed in the OS at:
    /usr/lib/jvm/java-1.6.0/jre/lib/amd64/libnpjp2.so
    I googled how to configure Java Plugin for FF 6 for Fedora 13 and the trick was to create a soft link from /home/<userID>/.mozilla/plugins to the above libnpjp2.so

    AVtech wrote:
    . . . If a person can't get an answer here I don't know where else to turn since Sun certainly wouldn't offer tech support for a free product . . .These forums are user forums, and only occasionally visited by Sun employees. Sun does provide Java technical support options, although (of course) at a charge.
    See:
    http://developers.sun.com/services/
    . . . I guess we'll just use JRE 5 until it's unsupported, whenever that will be. I'm still waiting for an answer on that question, too. See:
    http://java.sun.com/products/archive/eol.policy.html
    http://www.sun.com/service/eosl/
    This document (part IV and Appendix) has some debugging and troubleshooting information that may allow someone involved in the problem to resolve the cause:
    See:
    http://java.sun.com/javase/6/docs/technotes/guides/plugin/developer_guide/contents.htm
    Any steps that you can take to isolate the problem to specific Java versions, browsers, applets, web sites, operating systems (and versions), etc, would enhance the possibility of getting help.
    You can try the applets at this Sun location and see if any of them are "slow".
    See:
    http://java.sun.com/javase/6/docs/technotes/samples/demos.html

  • How can I use Seeburger java functions on SAP XI's user defined functions?

    Hi All,
    As my title implies; how can I use Seeburger java functions on SAP XI's user defined functions?  I've tried searching over the net in tutorials regarding this topic but I failed to find one; can someone provide me information regarding my question? thanks very much.
    best regards,
    Mike

    Hi Mike !
    You should check your documentation about which java classes you need to reference in the "import" section of your UDF. And also deploy the java classes into the java stack or include them as a imported archive in integration repository...it should be stated in the seeburger documentation.
    What kind of functions are you trying to use?
    Regards,
    Matias.

  • How can I share a *.java source file across multiple projects in NetBeans?

    I'm sure this simple and a pretty common operation but how can I share a *.java source file across multiple projects in NetBeans? Right now I keep cut, coping and pasting the same source file between multiple projects to re-use the same code. But I could I make this source file a library file or something like that so that I could access it from any project. I assume this would be a generic operation but I mentioned NetBeans for clarity. Thanks.

    fiebigc wrote:
    I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    >I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    Create a class library.
    Write your code, compile it to .class files, put those class files in a .jar file and include the jar file in the classpath whenever you want to compile a project against it.

Maybe you are looking for

  • Can I send the entire contents of a mailbox to another person as a .zip?

    I have a mailbox folder (MobileMe) that I specifically created in Snow Leopard Mail to segregate several hundred emails from the rest of my inbox. I would like to send the entire contents of this folder to someone via MobileMe - is this possible? In

  • Convenient way to install Java3d API&Java1.4 jre at the same time?

    My Java3D program is embedded on Applet and I hope that anyone can run my program with only 1 installation(such that install Java1.4 jre and Java3D api at the same time...of course auto install all is best).Also,I have 2 link on my page..one is Java1

  • Regarding bdc back ground job

    hi,           i want to run the bdc from the program itself  not using any transaction           could u plz tell me the syntex clearly with comments.       very urgent plz.

  • RMS Installation using Retail Templates from RA

    Hi, I have pre-installed RA 13.2.3, and now I need to install RMS 13.2.3 in the same server (64 bit environment). So, I'm thinking of installing RMS in a different database instance in the same Oracle Software. Can I use the same Retail Template from

  • Cannot access Editor part of Photoshop Elements 13

    Just bought and installed Photoshop Elements 13. Organiser works fine but when attempting to use Editor it asks for sign in and then tries to connect to internet and fails although connection is fine otherwise.