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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:08:22+00:00 2026-05-30T12:08:22+00:00

I am using this code to read data from a webpage : public class

  • 0

I am using this code to read data from a webpage :

public class ReadLatex {
public static void main(String[] args) throws IOException {
    String urltext = "http://chart.apis.google.com/chart?cht=tx&chl=1+2%20\frac{3}{4}";
    URL url = new URL(urltext);
    BufferedReader in = new BufferedReader(new InputStreamReader(url
            .openStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null) {
        // Process each line.
        System.out.println(inputLine);
    }
    in.close();
   }
}

The webpage gives the image for a latex code in the URL.

I am getting this exception:

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: http://chart.apis.google.com/chart?
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at ReadLatex.main(ReadLatex.java:11)

Can anyone tell why I am having this problem and what should be the solution for this?

  • 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-30T12:08:24+00:00Added an answer on May 30, 2026 at 12:08 pm

    Your problem is that you are using a \ (backslash) in a string which in Java is a escape character. To get an actual \ you need to have two of them in your string. So:

    Wanted text: part1\part2
    

    you need to have

    String theString = "part1\\part2";
    

    So you actually want

    String urltext = "http://chart.apis.google.com/chart?cht=tx&chl=1+2%20\\frac{3}{4}";
    

    Also, when you succeed with your request you get back an image (png) which should not be read with a reader which will try to interpret the bytes as characters using some encoding and this will break the image data. Instead, use the input stream and write the content (bytes) to a file.

    A simple example without error handling

    public static void main(String[] args) throws IOException {
        String urltext = "http://chart.apis.google.com/chart?cht=tx&chl=1+2%20\\frac{3}{4}";
        URL url = new URL(urltext);
    
        InputStream in = url.openStream();
        FileOutputStream out = new FileOutputStream("TheImage.png");
    
        byte[] buffer = new byte[8*1024];
        int readSize;
        while ( (readSize = in.read(buffer)) != -1) {
            out.write(buffer, 0, readSize);
        }
        out.close();
        in.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to read data from Oracle Database. That data stored
I'm using this code to return some string from a tcpclient but when the
I wan't to load some data from my XML file using this function: public
I am currently using this code to input data from numerous files into R:
I am using the following code to read attendance data from a biometric device:
While using this code to serialize an object: public object Clone() { var serializer
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I'm using this code, to make a request to a given URL: private static
I'm using this code from Microsoft to play audio notifications for my application. It's
I am specifically trying to read data from an SNMP port in python using

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.