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 8272655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:12:06+00:00 2026-06-08T07:12:06+00:00

I have the following code: private char[] headerToWrite; protected String workingFileName; private void writeHeaderToFile()

  • 0

I have the following code:

private char[] headerToWrite;
protected String workingFileName;

private void writeHeaderToFile()
{
    try
    {
        String completeFile = new String(headerToWrite);

        File myFile = new File(workingFileName);

        FileOutputStream fOut = new FileOutputStream(myFile);

        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);

        myOutWriter.append(completeFile);
        myOutWriter.close();
    }
    catch (IOException ioe) 
    {
        ioe.printStackTrace();
    }
}

In the above code, the variable headerToWrite contains an array, where the first few values are: [1, Q, H, S, , 4, ±, Q, .....]. This in hex is [31, 51, 48, 53, 01, 34, B1, 51...].

It is used to create a string completeFile which = 1QHS 4±Q…

However, when the file is being written, the file contains 1QHS 4űQ….. which in hex is [31 51 48 53 01 34 c2 b1 51]….

I couldn’t understand why there was an additional c2 but I discovered that the bytes inside myOutWriter were as follows: [49, 81, 72, 83, 1, 52, -62, -79, 81]….

The interesting point here is the -62, -79 which seems to be responsible for c2, b1. For it to work, -62, -79 should just be 177, which is the decimal for b1. Interestingly 177 + 79 is 256.

So evidently, in the transfer from ascii characters in completeFile to bytes in myOutWriter, c2 is being added.

I was wondering if anyone could explain why and how to fix it.

Thanks

  • 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-08T07:12:08+00:00Added an answer on June 8, 2026 at 7:12 am

    The -79 can be explained by overflow. As byte is a signed char and 177 > 127 (which is the maximal value for a byte), it will overflow and -79 is the result. I can not really explain the -62, but you are clearly using the wrong encoding (probably UTF-8). Try using a different encoding (ISO 8859-1 might do the trick).

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

Sidebar

Related Questions

I have the following code: private String foo; public void setFoo(String bar) { foo
I have the following code: private void _DoValidate(object sender, DoWorkEventArgs e) { this.BeginInvoke(new MethodInvoker(()
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have the following code: private void WatchFileForChanges() { if (fileInfo.Directory != null) {
I have a file encrypted using the following code in c: unsigned char ckey[]
i have the following code: Private Sub TxtPStof_KeyPress(ByVal sender As System.Object, ByVal e As
I have the following code: Private Sub SortWorksheet(ByVal sheet As Worksheet) Dim sStartColumn Dim
i have the following code Private Sub select_color_Click(ByVal sender As System.Object, ByVal e As

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.