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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:59:09+00:00 2026-06-15T20:59:09+00:00

Can we write Unicode Data in a File with ByteStreams? My code is: public

  • 0

Can we write Unicode Data in a File with ByteStreams?
My code is:

 public static void main(String[] args) throws Exception {

    String str = "Русский язык ";
    FileOutputStream fos = new FileOutputStream("file path");
    fos.write(str.getBytes());
    fos.flush();
    fos.close();
}

Here i am using a byte stream to write unicode data, but it is writing properly.I am new to java but i have read that byte streams do not support unicode characters. So, why does it is working in this case?

  • 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-15T20:59:11+00:00Added an answer on June 15, 2026 at 8:59 pm

    i have read that byte streams do not support unicode characters.

    Either you have used a bad source of information or you have probably misunderstood something. Byte streams support bytes. Therefore byte streams support anything that can be represented in bytes. Videos, text, pictures, music… If byte stream doesn’t support it, it cannot be used in a digital computer at all.

    The trick to represent those things in what is a simply a sequence of 1 and 0’s, is to use agreed upon rules. You would encode your text according to certain rules, and then the receiver can decode it back using the same rules.

    "Русский язык" can be represented as bytes in any encoding that supports cyrillic characters. In any of the encodings of unicode: UTF-8, UTF-16, UTF-32; Windows-1251, KOI8-R, KOI8-U, ISO-8859-5…

    That doesn’t mean these encodings are compatible with each other. They are all incompatible when it comes to encoding Cyrillic script, so text encoded in one the encodings, must strictly be decoded in that encoding.

    .getBytes() uses the platform default encoding, which happened to be a one that supported Cyrillic script. You might believe it’s UTF-8 but if you are on Windows, it’s far more likely to be Cp1251. Don’t fall into trap that just because you used “unicode characters”, that your files are physically encoded in an UTF encoding. That will lead to encoding problems.

    So always be explicit about encoding, so that your program works the same on any platform and so that you always know what encoding the files your program created are in. With your code, you could have done this:

    String str = "Русский язык ";
    FileOutputStream fos = new FileOutputStream("file path");
    fos.write(str.getBytes("UTF-8"));
    fos.flush();
    fos.close();
    

    Or as suggested by the other answer:

    String str = "Русский язык ";
    OutputStreamWriter osw = new OutputStreamWriter(
            new FileOutputStream("file path"), "UTF-8"
    );
    osw.write(str);
    osw.flush();
    osw.close();
    

    These are technically exactly the same; text is being converted to bytes according to UTF-8 rules.

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

Sidebar

Related Questions

Here's the code: public static void mergeAllFilesJavolution()throws FileNotFoundException, IOException { String fileDir = C:\\TestData\\w12;
Can anyone Provide a Simple Example to Read and Write in the Unicode File
Can anybody give any working example of how to read/write Unicode text files using
I can write my code in both the ways to achieve my objective, but
How can I show an nvarchar column that stores unicode data (Entered with the
I have a list of dictionaries containing unicode strings. csv.DictWriter can write a list
i'm using vbscript to extract data from db2 and write to file. Writing to
I have a GIF file (or any image format) in unicode form: >>> data
I have created the csv file through django. I have write the encoded data
You can write //google.com instead of http://google.com and https://google.com where // is relative to

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.