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

📄 listofnumbers2.java

📁 北大Java 语言程序设计 ppt课件及源码
💻 JAVA
字号:
import java.io.*;import java.util.Vector;public class ListOfNumbers2 {    private Vector victor;    private static final int size = 10;    public ListOfNumbers2() {        victor = new Vector(size);        for (int i = 0; i < size; i++)            victor.addElement(new Integer(i));	this.readList("infile.txt");	this.writeList();    }    public void readList(String fileName) {	String line = null;	try {	    RandomAccessFile raf = new RandomAccessFile(fileName, "r");	    while ((line = raf.readLine()) != null) {		Integer i = new Integer(Integer.parseInt(line));		System.out.println(i);		victor.addElement(i);	    }	} catch(FileNotFoundException fnf) {	    System.err.println("File: " + fileName + " not found.");	} catch (IOException io) {	    System.err.println(io.toString());	}    }    public void writeList() {        PrintWriter out = null;        try {            out = new PrintWriter(new FileWriter("outfile.txt"));                    for (int i = 0; i < victor.size(); i++)                out.println("Value at: " + i + " = " + victor.elementAt(i));        } catch (ArrayIndexOutOfBoundsException e) {            System.err.println("Caught ArrayIndexOutOfBoundsException: " +				 e.getMessage());        } catch (IOException e) {            System.err.println("Caught IOException: " + e.getMessage());        } finally {            if (out != null) {                System.out.println("Closing PrintWriter");                out.close();            } else {                System.out.println("PrintWriter not open");            }        }    }    public static void main(String[] args) {	new ListOfNumbers2();    }}

⌨️ 快捷键说明

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