导入导出
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导入导出相关的知识,希望对你有一定的参考价值。
一、加载文件
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
以上是关于导入导出的主要内容,如果未能解决你的问题,请参考以下文章