本帖最后由 曾宇 于 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);
- }
- }
-
- }
复制代码
|
|