Java中stdlib的使用
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