Results 1 to 2 of 2
  1. #1
    Ed
    Ed is offline Senior Member
    Join Date
    Jun 2007
    Posts
    110
    Rep Power
    0

    Default stream redirection

    I'm trying to redirect a data entries (text or string).
    I want to redirect this text or string to a Jtextarea. I found the method System.setOut(PrintStream out), but I don't know how can I visualize it in graphic component
    any ideas?

  2. #2
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    8

    Default

    I send you an example
    maybe it's useful to you or maybe not, this is a similar example that you want
    check it
    Java Code:
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.PrintStream ;
    import java.sql.Timestamp;
    
    /**
     * This class allow replaces standard output and error with a print stream that
     * copies its output to both the console and to a file.
    */
    public class IpsStandardStream extends PrintStream { 
    
        protected PrintStream out;
    
    
         */
        public IpsStandardStream(PrintStream out1, PrintStream out2) { 
            super(out1);
            this.out = out2;
        }
    
        public void write(byte buf[], int off, int len) {
            try {
                super.write(buf, off, len);
                out.write(buf, off, len); 
            } catch (Exception e) {
            }
        }
    
        public void flush() {
            super.flush();
            out.flush();
        }
    
    
         * 
         * @version 1.0
         */
        public static void replaceStandardOutput() {
    
            try {
                PrintStream outPut = new PrintStream(
                        new FileOutputStream(" out.log"));
                PrintStream tee = new IpsStandardStream(System.out, outPut);
                System.setOut(tee);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } 
    
        }
    
     
         * 
         * @version 1.0
         */
        public static void replaceStandardError() { 
    
            try {
                PrintStream err = new PrintStream(new FileOutputStream("error.log"));
                PrintStream tee = new IpsStandardStream(System.err, err);
                System.setErr(tee); 
    
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    
        }
    
        public static void main(String[] arg) {
    
            IpsStandardStream.replaceStandardOutput(); 
            IpsStandardStream.replaceStandardError();
    
            // Write to standard output and error and the log files
            Timestamp now;
            for (int i = 0; i < 1; i++) {
                now = new Timestamp( System.currentTimeMillis());
                System.out.println(now);
                System.out.println("welcome " + i);
                System.err.println(now);
                System.err.println("error " + i); 
            }
        }
    }

Similar Threads

  1. Output Redirection
    By Sixtease in forum New To Java
    Replies: 8
    Last Post: 12-29-2008, 11:18 AM
  2. JSP- Binary output stream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 10:06 AM
  3. JSP redirection script
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-07-2008, 11:33 AM
  4. redirection in jsp
    By valery in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-06-2007, 09:31 PM
  5. video stream
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-17-2007, 09:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •