DataInputStream in = new DataInputStream(new FileInputStream("f:/temp");
byte[] by=new byte[1024];
int len=0;
String str="";
while((len=in.read(by))>0){
str=str+new String(by,len);
}
byte[] by=new byte[1024];
int len=0;
String str="";
while((len=in.read(by))>0){
str=str+new String(by,len);
}
我现在在开发一个微型的数据库系统,所以对此比较熟悉,这样的事情我也做过,在此和大家一起分享:FileInputStream fileIn=new FileInputStream(path);
int ch;
String fileCon="";
//这个很重要,千万不可以不初始化,更不可以直接用null来初始化
while((ch=fileIn.read())>-1)
fileCont+=(char)ch;
return fileCon;//这里的内容就是你所要的了。我现在所用的就是这个方法
FileInputStream fileIn=new FileInputStream(path);
int ch;
String fileCon="";
在这里如果加一个
System.out.println("xxxx");
//这个很重要,千万不可以不初始化,更不可以直接用null来初始化
while((ch=fileIn.read())>-1)
fileCont+=(char)ch;在最后filecont中获得的文件内容会缺少第一个字符,怎么回事?
RandomAccessFile fileIn=new RandomAccessFile(myfile,"rw");
String []s=null;
for (int i=0;i<fileIn.length();i++){
s[]=fileIn.readLine();
System.out.println(s[i]);
}
定义的不好,可以这样:String s[] = new String(fileIn.length());
这样试试看,呵呵……