⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teststream.java

📁 J2ME 无线通信技术应用开发源代码
💻 JAVA
字号:
//程序名TestStream.java;
import java.io.*;
import javax.microedition.io.*;
public class TestStream {
  public static void main( String[] args ){
    try {
      String uri ="socket://127.0.0.1:80";
      StreamConnection conn = (StreamConnection) Connector.open( uri );
      // 发送HTTP请求...
      PrintStream out = new PrintStream(conn.openOutputStream());
      out.println( "GET /test.html HTTP/0.9\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( "Socket could not be opened" );
    } catch( IOException e ){
      System.out.println( e.toString() );
    }
    System.exit( 0 );
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -