byte b[] = new byte[256];
sfile.readFully( b,0,256);
nFileName="";
String tempStr=new String(b,"GBK");
for (int ii=0;ii<tempStr.length();ii++){
if (!((int)tempStr.charAt(ii)==0)){
nFileName=nFileName+tempStr.charAt(ii);
}else{
break;
}
}
sfile.readFully( b,0,256);
nFileName="";
String tempStr=new String(b,"GBK");
for (int ii=0;ii<tempStr.length();ii++){
if (!((int)tempStr.charAt(ii)==0)){
nFileName=nFileName+tempStr.charAt(ii);
}else{
break;
}
}
本文展示了一段Java代码示例,该代码用于从文件中读取256字节的内容,并采用GBK编码将其转换为字符串,进而解析出文件名。通过遍历字符串并检查每个字符,如果遇到空字符则停止读取,最终获取有效的文件名。
3480

被折叠的 条评论
为什么被折叠?



