diff --git a/src/j3/Telnet.java b/src/j3/Telnet.java index 03b5283..5b6b4be 100644 --- a/src/j3/Telnet.java +++ b/src/j3/Telnet.java @@ -1,6 +1,6 @@ package j3; -import java.io.InputStreamReader; +import java.io.DataInputStream; import java.io.OutputStream; import java.net.Socket; @@ -9,17 +9,16 @@ // プログラムの本体main public static void main(String[] args){ byte[] buff = new byte[1024];//配列の定義 - char[] cbuff = new char[1024];//配列の定義 Socket socket = null ;// サーバ接続用ソケット OutputStream outstr = null;// データ出力用オブジェクト - InputStreamReader instr = null;// データ読み取り用オブジェクト + DataInputStream din = null;// データ読み取り用オブジェクト boolean cont = true ; // 指定のポートに対して,ソケットを作成します // 入出力のストリームを作り,データ読み出しを準備します try{ socket = new Socket(args[0], Integer.parseInt(args[1])) ; outstr = socket.getOutputStream() ; //サーバへの送信用 - instr = new InputStreamReader(socket.getInputStream()) ; + din = new DataInputStream(socket.getInputStream()) ; } catch (Exception e) { System.err.println("Network error.") ; System.exit(1) ; @@ -41,9 +40,8 @@ cont = true ; while (cont) { try { - int n = instr.read(cbuff); - byte[] b = new String(cbuff).getBytes("UTF-8"); - System.out.write(b, 0, n) ; + int n = din.read(buff); + System.out.write(buff, 0, n) ; } catch(Exception e){ // 読み出し終了時にループも終了 @@ -51,7 +49,7 @@ } } try { - instr.close() ; + din.close() ; } catch(Exception e) { System.err.println("Close failed.") ; System.exit(1) ;