stdlib是java中的輸入輸出庫, 網址: http://introcs.cs.princeton.edu/java/stdlib
CSDN下載地址: http://download.csdn.net/detail/u012515223/6639631
把stdlib.jar放入Eclipse的dropins文件夾內,加載stdlib.jar, 位置: 項目->Properties, 如圖:

stdlib主要包含兩組函數: In & Out, StdIn & StdOut
In & Out 是通過參數進行讀取; StdIn & StdOut 是直接通過Console進行讀取;
具體代碼如下:
public class Stdlib
{
public static void main(String args[])
{
//In&Out的用法
Out out = new Out(System.out);
out.println("Read a file of integers: ");
In in = new In(args[0]);
int arr[] = in.readAllInts();
for (int i : arr) { out.print(i + " "); }
out.println("end");
//StdIn&StdOut的用法
StdOut.println("Please input an array of integers (Ctrl+Z end): ");
while(!StdIn.isEmpty()) {
int val = StdIn.readInt();
StdOut.print(val + " ");
}
StdOut.println("end");
}
}
輸出:
Read a file of integers: 1 2 3 4 5 6 7 8 9 10 end Please input an array of integers (Ctrl+Z end): 11 12 13 14 15 11 12 13 14 15 end