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

  • Home
  • SEARCH
  • 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 6993399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:45:34+00:00 2026-05-27T19:45:34+00:00

I have a program that I’m writing where I am using another company’s library

  • 0

I have a program that I’m writing where I am using another company’s library to download some reports from their website. I want to parse these reports before I write them to a file, because if they match certain criteria, I want to disregard them.

Problem is, their method, called download() returns a java.io.Reader. The only method available to me is

int read(char[] cbuf);

Printing this returned array out gives me meaningless characters. I want to be able to identify what character set I’m working with or convert it to a byte array but I can’t figure out how to do it. I’ve tried

//retrievedFile is my Reader object
char[] cbuf = new char[2048];
int numChars = retrievedFile.read(cbuf);
//I've tried other character sets, too
new String(cbuf).getBytes("UTF-8");

and I’m afraid to downcast to a more useful reader because I can’t know for sure if it will work or not. Any suggestions?

EDIT

When I say it prints out “meaningless characters”, I don’t mean that it looks like the example given by Jon Skeet. It’s really hard to describe because I’m not at my machine right now, but I think it’s an encoding issue. The characters seem to have indentations and structure similar to the look of the reports. I’ll try these suggestions as soon as I get back on Tuesday (I’m only an intern, so I haven’t bothered with setting up a remote account or anything).

  • 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-27T19:45:35+00:00Added an answer on May 27, 2026 at 7:45 pm

    Try this:

    BufferedReader in = new BufferedReader(retrievedFile);
    String line = null;
    StringBuilder rslt = new StringBuilder();
    while ((line = in.readLine()) != null) {
        rslt.append(line);
    }
    System.out.println(rslt.toString());
    

    Don’t typecast the Reader to any class because you don’t know the real type of it.
    Instead, use BufferedReader and pass Reader into it. And BufferedReader take any subclass of java.io.Reader as the argument so it is save to use it.

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

Sidebar

Related Questions

I have a program that I am writing, not too big. Apart from the
I have a program that generates some standard SQL like SELECT * FROM TEST
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that monitors debug messages and I have tried using a
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that uses the win32com library to control iTunes, but have
I have a program that works when, a file is opened with it using
I have a program that find all .csv reports file in a directory. This
I have a program that reads in a file and does some parsing 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.