黑马程序员技术交流社区
标题:
键盘记录操作
[打印本页]
作者:
曾宇
时间:
2014-7-28 15:20
标题:
键盘记录操作
本帖最后由 曾宇 于 2014-8-7 16:29 编辑
看了毕老师的视频,突然想写一个键盘记录的java代码,记录程序启动后所有的按键操作记录,并保存到C盘下。
import java.io.*;
class ReadIn
{
public static void main(String[] args) throws IOException
{
InputStream in = System.in;
BufferedOutputStream bufos = new BufferedOutputStream(new FileOutputStream("c:\\键盘记录.txt"));
StringBuilder sb = new StringBuilder();
while(true){
int ch = in.read();
if(ch=='\r')
continue;
if(ch=='\n'){
String s = sb.toString()
复制代码
bufos.write(s.getBytes());
bufos.close();
sb.delete(0,sb.length());
}else
sb.append((char)ch);
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2