⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboardtofile.java

📁 JAVA 键盘输入处理, 输出到文件,且可以循环输入
💻 JAVA
字号:

import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * User: lizh
 * Date: 2006-8-26
 * Time: 15:21:39
 * To change this template use File | Settings | File Templates.
 */
public class KeyboardToFile {
  public static String STR_FILENAME = "keyborad.txt";

  public static void main(String[] args) {
    KeyboardToFile keyClass = new KeyboardToFile();
    File file = null;
    try {
      file = keyClass.getFile(STR_FILENAME);
      String strInput = "";
      //get keyboard input
      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(isr);
      System.out.println("Please input string below:");
      strInput = br.readLine();
      //close the input stream
      if(br != null)
      {
        br.close();
      }
      keyClass.writeFile(file,strInput);
      System.out.println("Output is normal.");
    }
    catch (Exception e) {
      System.out.println(e);
    }
  }

  public File getFile(String strFileName) throws Exception {
    File file = new File(strFileName);
    if (file.exists()) {
      file.delete();
    }
    return file;
  }

  public void writeFile(File file, String str) throws Exception {
    FileOutputStream fo = new FileOutputStream(file);
    if (str != null) {
      fo.write(str.getBytes());
      fo.flush();
    }
    if (fo != null)
    {
      fo.close();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -