首页 > 代码库 > 导入导出
导入导出
一、加载文件
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
导入导出
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。