字节流
//2012.8.9
//IO流操作
import java.io.*;
public class IoDemo{
public static void main(String args[]){
OutputStream out = null; //输出流
InputStream in = null; //输入流
//目录
String locket = "g:" + File.separator + "java"
+ File.separator + "do" + File.separator + "temp.txt";
//输出过程
try{
File f = new File(locket);
out = new FileOutputStream(f);
String wrt = "Hello World!!!Hello World!!!Hello " +
"World!!!Hello World!!!Hello World!!!Hello World!!!";
byte b[] = wrt.getBytes();//转换为byte数组类型
out.write(b);
System.out.println("写入完成!");
out.close();
}catch(Exception e){
e.printStackTrace();
}
//输入过程
try{
File f = new File(locket);
in = new FileInputStream(f);
byte b[] = new byte[in.available()];//定义biye数组 长度为文件大小
in.read(b);
String wrt = new String(b,0,b.length);
System.out.println(wrt);
in.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
这样的话会不会有长度限制??是不是只能达到1024?
因篇幅问题不能全部显示,请点此查看更多更全内容