Solve the problem of Chinese garbled Characters During the connection of j2s.

Source: Internet
Author: User

The following code is from http://blog.csdn.net/hellogv/. for reference, see the source!

Package hello; import javax. microedition. MIDlet. *; import javax. microedition. lcdui. *; import javax. microedition. io. *; import Java. io. *; public class MIDlet extends MIDlet {private display; Public MIDlet () {display = display. getdisplay (this);} public void Startapp () {try {string uurl = "http://3g.pp.cn/phone/app/gpcx.jsp? SID = 1182917775043 & dirid = 03311317 & gpdm = 600156 "; stringbuffer responsemessage = new stringbuffer (); httpconnection Hc = (httpconnection) connector. open (uurl, connector. read_write); HC. setrequestmethod (httpconnection. post); dataoutputstream dos = HC. opendataoutputstream (); datainputstream Dis = new datainputstream (HC. openinputstream (); // --------------------------- key code -------------------------------- byte [] STR = new byte [1000]; // apply for a space dis from the memory. read (STR); // Save the returned read information in STR string content = bytestostring (STR ); // convert STR to a string // --------------------------- key code -------------------------------- Form F = new form ("HTTP test"); F. append (content); display. setcurrent (f);} catch (exception e) {}} // ------------------------- key function ----------------------------- Public String bytestostring (byte [] REC) {// read bytearrayinputstream BAIS = new bytearrayinputstream (REC); datainputstream Dis = new datainputstream (BAIS); string BTS = NULL; try {BTS = new string (REC, "UTF-8"); BAIS. close (); DIS. close ();} catch (exception e) {e. printstacktrace ();} return BTS;} // ----------------------- key function ----------------------------- public void pauseapp () {} public void destroyapp (Boolean unconditional ){}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.