Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:14:31+00:00 2026-06-02T15:14:31+00:00

I wrote this code to convert binary data to ascii , now I want

  • 0

I wrote this code to convert binary data to ascii , now I want to write the console result into a textfile output.txt . it runs but the problem is it prints the first line into console and start writing the output to textfile from the second line , on other words it skip the fisr line !

public static void main(String args[])
  {
  try{
  // Open the file that is the first 
  // command line parameter
  FileInputStream fstream = new FileInputStream("textfile.txt");
  // Get the object of DataInputStream
  DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String strLine;
  //Read File Line By Line
  while ((strLine = br.readLine()) != null)   {

      String input = br.readLine();
            String output = "";
            for(int i = 0; i <= input.length() - 8; i+=8)
            {
                int k = Integer.parseInt(input.substring(i, i+8), 2);
                output += (char) k;
            }

                System.out.println("string: " + output);
          orgStream = System.out;
          fileStream = new PrintStream(new FileOutputStream("d:/output.txt",true));

          // Redirecting console output to file
          System.setOut(fileStream);


              } 
  //Close the input stream
  in.close();
    }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
  }
  }
}

these line are responsible for writing the result into output.txt:

 System.out.println("string: " + output);
          orgStream = System.out;
          fileStream = new PrintStream(new FileOutputStream("d:/output.txt",true));

          // Redirecting console output to file
          System.setOut(fileStream);

how can I save output in eclipse to be able to use that again ? now I save in D drive

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:14:32+00:00Added an answer on June 2, 2026 at 3:14 pm

    the code
    System.err.println("Error: " + e.getMessage()); will write to the error stream and not the out stream..

              System.setOut(out);
    

    here you are setting the out stream, the err stream still defaults to the console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert function object to function. I wrote this code, but it
I just wrote this code to convert a GUID into a byte array. Can
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this python code in an attempt to convert objects to a string
I have wrote this code: $final = array( ($data[0] - $data[1]), ($data[1] - $data[2]),
I'm trying to convert a string I read with this code to binary and
I'm trying to write a code that converts a number to binary, and this
I wrote this code in C# to encrypt a string with a key: private
I wrote this code. The constructor works normally, but in the destructor I get
I wrote this code that compiles on Solaris gcc it works fine too for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.