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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:12:27+00:00 2026-05-15T16:12:27+00:00

Given this code in Java: FileOutputStream os = new FileOutputStream(/tmp/test.dat); os.write(0x14); os.write(0xfe); os.write(0xae); os.write(String.valueOf((char)

  • 0

Given this code in Java:

    FileOutputStream os = new FileOutputStream("/tmp/test.dat");
    os.write(0x14);
    os.write(0xfe);
    os.write(0xae);

    os.write(String.valueOf((char) 0x14).getBytes("UTF-8"));
    os.write(String.valueOf((char) 0xfe).getBytes("UTF-8"));
    os.write(String.valueOf((char) 0xae).getBytes("UTF-8"));

    os.write("\u0014".getBytes("UTF-8"));
    os.write("\u00fe".getBytes("UTF-8"));
    os.write("\u00ae".getBytes("UTF-8"));

    os.close();

Can somebody explain to me why the first 3 bytes in test.dat are

14 fe ae

while the output from the last 6 os.write()’s are

14 c3 be c2

Basically, I want to literally output the bytes 14 fe ae. I was storing these values as a String constant, and writing the value of these constants to a UTF-8 file, but 14 c3 be c2 was output instead. There’s obviously a gap in my understanding in how these byte sequences are converted in Java.

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-05-15T16:12:28+00:00Added an answer on May 15, 2026 at 4:12 pm

    It gives:

    0x 14 fe ae 14 c3 be c2 ae 14 c3 be c2 ae
    

    The first three bytes are obvious. They’re just being outputted literally. For the next three, you should remember that char in Java represents a UTF-16 code unit, not a byte. So you’re first creating the Unicode code units U+0014, U+00FE, U+00AE, then converting each to UTF-8. U+0014 is 0x14 in UTF-8 (since it’s also ASCII), but U+00FE is 0xC3 0xBE and U+00AE is 0xC2 0xAE.

    You’re creating the same characters again in the next three lines.

    The bottom line is that if you want to store literal bytes, just use a byte array.

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

Sidebar

Related Questions

Given this code in Java: int i,j; String[] names; names[0] = new String(mary); names[1]
Given this code, tableButton = new JButton(new ImageIcon(80F_FG2015.GIF)); how would I get that String
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Given this Java code: class Account { private Integer number = 0; public synchronized
Given this Java code, this outputs 0 and 4 : class A{ A() {
Given this Java code: int fst = 5; int snd = 6; if(fst ==
Given this code : package db; import java.sql.*; public class Main { public static
i have this code to download a single file . import java.io.FileOutputStream; import java.io.IOException;

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.