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

📄 filelist.java

📁 it contains the practical programs in our college
💻 JAVA
字号:
import java.util.*;import java.io.*;public class FileList {    public static void main(String[] args) {        final int assumedLineLength = 50;        File file = new File(args[0]);        List<String> fileList =             new ArrayList<String>((int)(file.length() / assumedLineLength) * 2);        BufferedReader reader = null;        int lineCount = 0;        try {            reader = new BufferedReader(new FileReader(file));            for (String line = reader.readLine(); line != null;                    line = reader.readLine()) {                fileList.add(line);                lineCount++;            }        } catch (IOException e) {            System.err.format("Could not read %s: %s%n", file, e);            System.exit(1);        } finally {            if (reader != null) {                try {                    reader.close();                } catch (IOException e) {}            }        }        int repeats = Integer.parseInt(args[1]);        Random random = new Random();        for (int i = 0; i < repeats; i++) {            System.out.format("%d: %s%n", i,                    fileList.get(random.nextInt(lineCount - 1)));        }    }}

⌨️ 快捷键说明

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