1
回答
java从服务器端下载pdf的问题
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

从服务器端用http流下载到本地的pdf文件为什么打开不了

 

 

 

 String saveDir=Environment.getExternalStorageDirectory()+"/DownFile";  
	        File file1=new File(saveDir);  
	        if (!file1.exists()) {  
	            file1.mkdir();  
	        }  
	        
  String savePath = saveDir + "/" + BookIDFactory.buildBookId() +".pdf";  
	        
	        booklocaluri = savePath;
	        
	        File file =new File(savePath);  
	        if (!file.exists()) {  
	            try {  
	                file.createNewFile();  
	            } catch (IOException e) {   
	                e.printStackTrace();  
	            }     
	        }  
	        
	        try {  
	            outputStream=new FileOutputStream(file);  
	            byte [] buffer=new byte[1024*4];  
	            fileLength=connection.getContentLength();
	            while (completeLength < fileLength) {  
	                outputStream.write(buffer);  
	                completeLength += inputStream.read(buffer); 
	                int i = (completeLength*100)/fileLength; 	               
	            } 
	            outputStream.flush();
	            outputStream.close();
	        } catch (FileNotFoundException e) {  
	            e.printStackTrace();  
	        } catch (IOException e) {   
	            e.printStackTrace();  
	        }   

 

举报
顶部