Article View: borland.public.jbuilder.java.language
Article #19499Converting byte to string
From: Tony Pitman
Date: Fri, 30 Jan 1998 00:00
Date: Fri, 30 Jan 1998 00:00
41 lines
1598 bytes
1598 bytes
I have the following code:
URL u = null;
try
{
String isapiurl = m_ISAPIURL + "?AccessMode=GET" + "&CompanyName=" +
m_CompanyName + "&Category=" + m_Category + "&";
u = new URL(isapiurl);
}
catch(MalformedURLException e)
{
m_URLContent = "URL not specified correctly";
}
try
{
if (u != null)
{
byte b[] = new byte[10000];
u.openStream().read(b);
int i;
m_URLContent = new String(b, "8-bit");
m_URLContent is a String. As you can see it opens a URL connection to a
site with some parameters. It then uses openStream to read the response.
I then want to take the response, which comes in the form a byte, and
convert it to a String. The String constructor I used to use was the
String(b, 0) which has since been depreciated. I decided to try the new
character encoding version, but do not know what the valid encoding strings
are.
Can someone either tell me an easier way to open a URL connection and read
the response into a string or what the posible character-encoding strings
are? If the latter, I especially need the one to convert from byte to
string.
thanks, Tony
Technical Details
Message-ID:
<01bd2d3f$c3029d80$62d4adcf@tonylaptop>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,25e7a650429f8107,start X-Google-Attributes: gidf74b3,public From: "Tony Pitman" <tony@shatalmic.com> Subject: Converting byte to string Date: 1998/01/30 Message-ID: <01bd2d3f$c3029d80$62d4adcf@tonylaptop> X-Deja-AN: 320479861 Organization: None Newsgroups: borland.public.jbuilder.java.language