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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:51:38+00:00 2026-05-22T20:51:38+00:00

I am sorry if it has been asked before. I am trying to process

  • 0

I am sorry if it has been asked before. I am trying to process a text file using Java. The text file is exported from MS SQLServer. When I open it in PSPad (sort of text editor in which I can view any file in hex format), it tells me that my text file is in UTF-16LE. Since I am getting it from someone else, it is quite possible.

Now my Java program is not able to deal with that format. So I wanted to know if there is any way by which I can either convert my text file in ASCII format or do some preprocessing or anything? I CAN modify the file.

Any help is greatly appreciated.

Thanks.

EDIT 1

I wrote this program, but it is not working as expected. If I see the output file in PSPad, I can see each character as a 2-byte char, e.g. ‘2’ is 3200 instead of just 32; ‘M’ is 4D00 instead of just 4D, etc. The though says the encoding of output file is UTF-8. I am kind of confused here. Can anyone tell me what am I doing wrong?

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

        try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream(
                    "input.txt");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-16LE"));
            String strLine;
            // Read File Line By Line
            while ((strLine = br.readLine()) != null) {
                // Write to the file
                writeToFile(strLine);
            }
            // Close the input stream
            in.close();
        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

        System.out.println("done.");
    }

    static public void writeToFile(String str) {
        try {
            OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("output.txt", true), "UTF-8");
            BufferedWriter fbw = new BufferedWriter(writer);
            fbw.write(str);
            fbw.close();
        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    } 

EDIT 2

Here are the snapshots:

input file in PSPad (a free hex viewer)enter image description here

output file in PSPad enter image description here

this is what i was expecting to see:
enter image description here

  • 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-05-22T20:51:39+00:00Added an answer on May 22, 2026 at 8:51 pm

    Just found a solution.

    http://www.fileformat.info/convert/text/utf2utf.htm

    Lets you upload and convert between the encodings.

    Its not a permanent solution though, since my file is 700MB+. So I will try out some solutions posted by others.

    This small software helps:

    http://www.kalytta.com/tools.php

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

Sidebar

Related Questions

Sorry if this has been asked before, but I'm wondering what the best memory
(I’m sorry if this has been asked before; the search feature seems to be
First of all, sorry if this has been asked before. I've done a pretty
I'm sorry if this questions has been asked before, but I couldn't find an
Sorry if this has been asked before, I did check but couldn't find anything...
I'm sorry if this has been asked before, but I'm in kind of a
Sorry if this question has been asked before. On my search through SO I
sorry if this questions is overly basic or has been asked before but I
Sorry if this has been asked before but I've tried searching and can't find
Sorry if this has been asked before, but as I understand it, in C++11,

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.