java从入门到精髓 - IO输入输出FileInputOutputStream
时间:2010-08-31 来源:叮当小马
import java.io.*;
public class FileInputOutputStream {
public static void main(String[] args) {
File file = new File("E:/workspace/Java从入门到精通/mynote.txt");
try
{
FileOutputStream out = new FileOutputStream(file);
byte b[]= "我有一只小毛驴。".getBytes();
//byte b[]= str.getBytes();
System.out.println("b.length: "+b.length);
out.write(b);
out.close();
}catch(Exception e)
{
e.printStackTrace();
}
try
{
FileInputStream in = new FileInputStream(file);
byte b [] = new byte[1024];
int len = in.read(b);
System.out.println("文件中的信息:"+new String(b,0,len));
in.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}