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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:52:51+00:00 2026-06-14T04:52:51+00:00

I have problem with reading text form InputStream connected with the URL. I’m using

  • 0

I have problem with reading text form InputStream connected with the URL.
I’m using Scanner to read text but it looks like there were no text formating.

Here is code

 connection = new URL(finalURL).openConnection();
 connection.connect();
 inStream =  connection.getInputStream();
 in = new Scanner(inStream);
 while(in.hasNextLine()){
   line = in.nextLine();
   System.out.println(line);
}

I have omitted try catch clause.
The output is some like this:
µtÂ÷BPv§2d
ŐüUŘ}ĎÓăR

While it shoud be like this:
06MAGNA,20121109,0.26,0.27,0.25,0.27,37820
08OCTAVA,20121109,0.73,0.75,0.73,0.73,12244

When I have saved it on disk as txt file and then use Scanner it works fine but via URL it doesn’t. Can anyone help me?

  • 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-14T04:52:52+00:00Added an answer on June 14, 2026 at 4:52 am

    I think its happening because of charset different in the input stream and default charset of scanner. Try passing the Charset in the Scanner constructor.

             in = new Scanner(inStream, "UTF-8");//set the appropriate charset
    

    EDIT: You can get content encoding using connection.getContentEncoding().

    Update your scanner instantiation as:

             in = new Scanner(inStream, connection.getContentEncoding());
    

    EDIT1: To deal with gzip input stream, use GZIPInputStream as below:

          inputStream = new GZIPInputStream(connection.getInputStream());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using BufferedReader to read a .csv file. I have no problem reading the
i have one problem controlling checkbox, i'm reading, and searching about the topic but
I dont know much about joomla but I have a problem. I started reading
I have a simple form that submits text to my SQL table. The problem
Newbie question. In Python 2.7.2., I have a problem reading text files which accidentally
I have a Java problem that involves reading a text file and check that
I have a problem reading a txt file to insert in the mysql db
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
I have a problem with reading some gml files in c#. My files do
I have some problem with reading from sqlite3 database. -(void) readMessengesFromDatabase { sqlite3 *database;

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.