📄 testconnection.java
字号:
//程序名TestConnection.java,项目TestConnection
//测试CLDC的基本连接框架:StreamConnection, ContentConnection
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class TestConnection extends MIDlet {
public void startApp() {
try {
testStreamConnection();//测试StreamConnection
//testContentConnection();//测试ContentConnection
} catch (IOException e) {
System.out.println("error.");
}
notifyDestroyed();//测试完毕后关闭应用程序
}
void testStreamConnection() throws IOException{
try {
String uri ="socket://localhost:8080";
StreamConnection conn = (StreamConnection) Connector.open( uri );
// 发送HTTP请求...
PrintStream out = new PrintStream(conn.openOutputStream());
out.println( "GET /j2me/html/TestConnection.html HTTP/1.1\r\n" );
out.flush();
// 获取原始HTTP应答...
InputStream in = conn.openInputStream();
int ch;
while( ( ch = in.read() ) != -1 ){
System.out.print( (char) ch );
}
in.close();
out.close();
conn.close();
} catch( ConnectionNotFoundException e ){
System.out.println( "Http could not be opened" );
}
}
public void pauseApp() {
}
public void destroyApp( boolean unconditional ) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -