[java]代码库
/**
* read()方法
* Reads a byte of data from this input stream. This method blocks
* if no input is yet available.
* 返回值 the next byte of data, or <code>-1</code> if the end of the file is reached.
* <p/>
* 该函数返回一个int类型,范围从0至255,如果到达流末尾,返回-1。
* 通过ByteArrayInputStream的源码可以看到是如何从byte转到int
* public synchronized int read() {
* return (pos < count) ? (buf[pos++] & 0xff) : -1;
* }
*/
@Test
public void test1() throws Exception {
FileInputStream in = new FileInputStream("E:\\key\\test.txt");
FileOutputStream out = new FileOutputStream("E:\\key\\test2.txt");
/**
* 返回值为下一个字节,如果没有数据,返回-1
*/
int temp;
while ((temp = in.read()) != -1) {
/**
* 参数: the byte to be written.
*/
out.write(temp);
}
}//源代码片段来自云代码http://yuncode.net