[問題] 請問一個輸入的問題

看板java作者 (加油)時間17年前 (2009/01/14 00:41), 編輯推噓4(407)
留言11則, 3人參與, 最新討論串1/1
請問我想要鍵盤鍵入後 馬上將這個字元傳到outputstream去 並且不要在螢幕上顯示 這樣我從鍵盤來的input要怎麼寫啊? outputstream取得的方法用write()可以吧? 我想要從bbs上取資料 讀的部份ok 但不知該怎麼傳資料給bbs 另外就是 方向鍵的問題 不知該怎麼解決 (不過有其他鍵可以取代 沒解決也沒關係) 附上程式碼 import java.io.*; import java.net.*; //開個socket接收/傳送資料至bbs,接收和傳送要放在兩個不同的threads class BBSsend extends Thread{ OutputStream os; //constructor BBSsend(Socket socket) throws Exception{ os=socket.getOutputStream(); } public void run(){ try{ while(true){ os.write(new BufferedReader( new InputStreamReader(System.in)).read()); } //↑這邊搞好久都搞不定...拜託了 } catch (Exception e){} } } public class BBS{ public static void main(String[] args) throws Exception{ String server="ptt.cc"; Socket socket=new Socket(server,23); BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream())); BBSsend send=new BBSsend(socket); send.start(); while(true){ System.out.println(br.readLine()); } } } -- ▄▄ ▄▄ ▄▄▄ ▄▄▄ ▄ ▄ ▄▄ ▄▄ ▄▄ ▄▄▄ ▄▄▄▄ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.213.190 ※ 編輯: ozone 來自: 140.112.213.190 (01/14 00:41)

01/14 02:09, , 1F
你是要實做 BBS client program 嗎?
01/14 02:09, 1F

01/14 02:47, , 2F
算是吧 不過顯示畫面不重要 只要能讓程式讀就好了
01/14 02:47, 2F

01/14 02:48, , 3F
還要可以對bbs做input...
01/14 02:48, 3F

01/14 03:32, , 4F
方向鍵跟一些組合鍵可參考我寫的對照表
01/14 03:32, 4F


01/14 23:29, , 6F
01/14 23:29, 6F

01/15 12:34, , 7F
後來用InputStream.write(String.getBytes("UTF-8"))成功了!
01/15 12:34, 7F

01/15 23:35, , 8F
我不知道你成功了什麼?InputStream 怎麼會有支援 write?!
01/15 23:35, 8F

01/15 23:36, , 9F
要 output 中文字到台灣的 BBS 要使用 Big5 編碼
01/15 23:36, 9F

01/16 01:40, , 10F
打錯了 是OutputStream @@" getBytes我是看別人用的..
01/16 01:40, 10F

01/18 04:32, , 11F
真的! 輸入英文的時候UTF-8沒問題 但中文會變亂碼 感謝s大!
01/18 04:32, 11F
文章代碼(AID): #19RCGt57 (java)