作者ozone (加油)
看板java
標題[問題] 請問一個輸入的問題
時間Wed Jan 14 00:41:25 2009
請問我想要鍵盤鍵入後
馬上將這個字元傳到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)
推 sbrhsieh:你是要實做 BBS client program 嗎? 01/14 02:09
→ ozone:算是吧 不過顯示畫面不重要 只要能讓程式讀就好了 01/14 02:47
→ ozone:還要可以對bbs做input... 01/14 02:48
推 TonyQ:方向鍵跟一些組合鍵可參考我寫的對照表 01/14 03:32
→ ozone:後來用InputStream.write(String.getBytes("UTF-8"))成功了! 01/15 12:34
推 sbrhsieh:我不知道你成功了什麼?InputStream 怎麼會有支援 write?! 01/15 23:35
→ sbrhsieh:要 output 中文字到台灣的 BBS 要使用 Big5 編碼 01/15 23:36
→ ozone:打錯了 是OutputStream @@" getBytes我是看別人用的.. 01/16 01:40
→ ozone:真的! 輸入英文的時候UTF-8沒問題 但中文會變亂碼 感謝s大! 01/18 04:32