Eclipe Console

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    Eclipe Console

    Good Day!
    I have one large real application (numerical) and build and run it using eclipse.
    Eclipse console gives VERY long list of output and I can see only half of them.
    How to get the whole (complete) output viewed in console?
    Maybe I need to export all the result in text or whatever?
    Please help me. TIA
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shana07
    Good Day!
    I have one large real application (numerical) and build and run it using eclipse.
    Eclipse console gives VERY long list of output and I can see only half of them.
    How to get the whole (complete) output viewed in console?
    Maybe I need to export all the result in text or whatever?
    Please help me. TIA
    Using the console for out put is not the correct thing to do for large applications. You should use a text file instead. Write a static utility method called say.
    Code:
    public static printToFile(String s)
    , and use that to log all events. In that method you simply open a file for appending and append the String s to that file. You then replace your System,out.prin tln statements with the ClassName.print ToFile method.

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #3
      Originally posted by r035198x
      Using the console for out put is not the correct thing to do for large applications. You should use a text file instead. Write a static utility method called say.
      Code:
      public static printToFile(String s)
      , and use that to log all events. In that method you simply open a file for appending and append the String s to that file. You then replace your System,out.prin tln statements with the ClassName.print ToFile method.
      Could you please check my code: what's wrong with it....
      In my text file, only last line was printed.
      Code:
       public static void printToFile(String s) 
        {
            try
              {
              FileOutputStream fout;		
      	    fout = new FileOutputStream ("output.txt");    
                  new PrintStream(fout).println (s);   
      	    fout.close();
              }
              catch (IOException exc)
              {
                  System.out.println("CAN'T OPEN THIS FILE !!!");
              }     
         
        }

      Comment

      • N002199B
        New Member
        • Feb 2007
        • 41

        #4
        Originally posted by shana07
        Could you please check my code: what's wrong with it....
        In my text file, only last line was printed.
        Code:
         public static void printToFile(String s) 
          {
              try
                {
                FileOutputStream fout;		
        	    fout = new FileOutputStream ("output.txt");    
                    new PrintStream(fout).println (s);   
        	    fout.close();
                }
                catch (IOException exc)
                {
                    System.out.println("CAN'T OPEN THIS FILE !!!");
                }     
           
          }
        It's in the constructor of your FileOutputStrea m. It comes, by default overloaded, ie many ways to call the constructor by varying the parameter-list passed to the same constructor name.

        The one you are using overrides everything in a file it is writing to each time u call it. Use the one with two arguemnts, the string file_name and the boolean append_option set to true. This will allow u to have th whole output in tha file.

        Try this

        try
        Code:
         public static void printToFile(String s) 
          {
              try
                {
                FileOutputStream fout;		
        // N00199B added here
        	    fout = new FileOutputStream ("output.txt",true);    
                    new PrintStream(fout).println (s);   
        	    fout.close();
                }
                catch (IOException exc)
                {
                    System.out.println("CAN'T OPEN THIS FILE !!!");
                }     
           
          }
        [/QUOTE]

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by shana07
          Could you please check my code: what's wrong with it....
          In my text file, only last line was printed.
          Code:
           public static void printToFile(String s) 
          {
          try
          {
          FileOutputStream fout;		
          	 fout = new FileOutputStream ("output.txt"); 
          new PrintStream(fout).println (s); 
          	 fout.close();
          }
          catch (IOException exc)
          {
          System.out.println("CAN'T OPEN THIS FILE !!!");
          } 
           
          }
          Do not use streams for writing to a file! Use BufferedWriter and FileWriter.
          The reason you get one line printed is probably because you are opening the file in overrride mode. Open it in append mode using FileWriter as follows

          Code:
           FileWriter fos = new FileWriter("foo.txt", true);
          Then wrap the fos variable in a BufferedWriter and write to it.

          Comment

          • dav3
            New Member
            • Nov 2006
            • 94

            #6
            Originally posted by r035198x
            Code:
             FileWriter fos = new FileWriter("foo.txt",[b] true[/b]);

            Had this issue in a recent project:)

            Comment

            Working...