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

📄 readtext.java

📁 Java学习源代码检索系统免费版
💻 JAVA
字号:
//==============================================================
// ReadText.java - Reads a text file using typed input
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import java.io.*;

public class ReadText {

 // Input a string
 public static String readLine()
  throws IOException {
  BufferedReader br = 
   new BufferedReader(new InputStreamReader(System.in));
  return br.readLine();
 }

 // Prompt for and input a string
 public static String readLine(String prompt)
  throws IOException {
  System.out.print(prompt);
  return readLine();
 }

 // Construct File object for named file
 public static File getFileForFilename(String filename)
  throws IOException {
  File fi = new File(filename);
  // Do not move the following statements;
  // order is critical
  if (!fi.exists())
   throw new IOException(fi.getName() + " not found");
  if (!fi.isFile())
   throw new IOException(fi.getName() + " is not a file");
  return fi;
 }
 
 // Main program method
 public static void main(String args[]) {
  String filename;
  try {
   // Get pathname from command line or prompt user
   if (args.length > 0)
    filename = args[0];
   else
    filename = readLine("Read what text file? ");
   File fi = getFileForFilename(filename);
   FileInputStream fin = new FileInputStream(fi);
   BufferedReader bin = 
    new BufferedReader(new InputStreamReader(fin));
   String line = bin.readLine();  // Read first line
   while (line != null) {         // Loop until end of file
    System.out.println(line);     // Print current line
    line = bin.readLine();        // Read next line
   }
  } catch (IOException e) {            // Trap exception
   System.err.println(e.toString());   // Display error
  }
 }
}

⌨️ 快捷键说明

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