首页 > 代码库 > 导入导出

导入导出

一、加载文件

  1. FileInputStream & InputStream 区别:

    InputStream 不可以读取文件,它是一个 Abstract 的类,不能实例化,是所有输入流的基类;

    FileInputStream 是 InputStream 的一个实现类,用于读取诸如图像数据之类的原始字节流。

  2. FileInputStream & FileReader & BufferedReader 区别:

    技术分享  

// FileInputStream



File file = new File(path); FileInputStream fis= new FileInputStream(file);

while((i=fis.read()) != -1){ System.out.println(i); }
// InputStreamReader
File file = new File(path);
FileInputStream fis= new FileInputStream(file);

InputStreamReader isr=new InputStreamReader(fis,"utf8");
while((i=isr.read()) != -1){ System.out.println((char)i); }
// BufferedReader
File file = new File(path);
FileInputStream fis= new FileInputStream(file);

InputStreamReader isr=new InputStreamReader(fis,"utf8");   
BufferedReader br=new BufferedReader(isr); String line; while((line=br.readLine()) != null){ System.out.println(line); }

二、下载

  ① 下载到指定目录

File file = new File(path);  
FileOutputStream out = new FileOutputStream(file);  

doc.write(out);  
out.close();  

  ② 直接下载

File file = new File(path);
response.setHeader("Content-Disposition", "attachment; filename="+new String(output.getBytes("gb2312"), "iso-8859-1"));

OutputStream out= response.getOutputStream();
doc.write(out);

此篇为学习笔记:

http://blog.csdn.net/zndxlxm/article/details/7405088

http://blog.csdn.net/moxie008/article/details/5663488

导入导出