日期:2014-05-20  浏览次数:20678 次

请教:java读入文件问题
编写一个GZip文件的解压程序,但是只能读出来其中一部分,就认为结束了(函数返回-1   )。经过分析认为是读的原文本文件中有结束符号,读不出文件所有内容,怎么办?  
各位大虾们有没有遇到过类似问题?  
谢谢了先!

------解决方案--------------------
真没遇到过这种情况,你是利用判断字符是不是结束符结尾的? 根据读入的字符数0判断结尾如何?参考下面的代码。
File file1 = new File( url1 ) ;
File file2 = new File( url2 ) ;
FileInputStream input = null ;
FileOutputStream output = null ;
try{
input = new FileInputStream( file1 ) ;
output = new FileOutputStream( url2 + "/ " + filename ) ;
byte[] b = new byte[1024 * 5] ;
int len ;
while( ( len = input.read( b ) ) != -1 ){
output.write( b, 0, len ) ;
}
output.flush() ;
}catch(Exception e){
throw e;
}finally{
try{
output.close() ;
input.close() ;
}catch( Exception ex ){
ex.printStackTrace();
}
}
}
不知道有没有用,LZ一定要回来告诉我一下结果阿。不行咱们再讨论。
------解决方案--------------------
照你这么说java写了关于这方面的方法也是多余了?