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

📄 main.java

📁 java的经典例子
💻 JAVA
字号:
import java.io.*;

class Main {
    public static void main(String[] args) {
        if (args.length != 1) {
            System.err.println("Usage: java Main <inputfile>");
            System.exit(-1);
        }
        try {
            File f = new File(args[0]);
            LineNumberReader in = new LineNumberReader(new FileReader(f));

            int charcount = (int)f.length();
            in.mark(charcount); // mark at beginning of stream
            in.skip(charcount); // skip to end of buffer
            int linecount = in.getLineNumber();

            System.out.println("file:\t" + args[0] +
                               "\nlines:\t" + linecount + 
                               "\nchars:\t" + charcount +
                               "\ncontent:");
            in.reset();        
            char[] buf = new char[100];
            int howmany = in.read(buf);

            // Echo characaters
            for (int i = 0; i < howmany; i++)
                System.out.write(buf[i]);
            System.out.println();

            // Indicate whether there are more
            if (charcount >= 100) 
                System.out.println("...");
            System.out.flush();         // flush output

            in.close();                 // closes all "downstream" readers
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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