输出结果:
字节流
OutputStream InputStream
FileOutputStream FileInputStream //一般情况下使用此方法进行文件读写,可以设置字节数组以提高效率,较常用
BufferedOutputStream BufferedInputStream //效率比上面一个高,字节缓冲流
字符流
Writer Reader
OutputStreamWriter InputStreamReader //用在需要以特定编码读写文件的情况
FileWriter FileReader //较为简洁的书写方法,相较于上面的方法,不能以特定编码方式读写,只能使用默认编码方法
BufferedWriter BufferedReader //字节缓冲流,速度较快,且有nextLine()/readLine()方法,较常用
OutputStreamWriter(FileOutputStream)
BufferedWriter(OutputStreamWriter)
BufferedWriter(OutputStreamWriter(FileOutputStream)) BufferedWriter(FileWriter )
字符打印流:PrintWriter pw=new PrintWriter(new FileWriter("文件路径"),true) //自动刷新流
文件转换流
FileInputStream fis=new FileInputStream("文件路径");
InputStreamReader isr=new InputStreamReader(fis,"GBK");
对象序列化流:ObjectOutputStream
类需要实现 serializable接口才能序列化
强烈建议申明:seriaVersionUID
对象反序列化流:ObjectInputStream
ObjectInputStream(FileInputStream("文件路径"))
Properties: map集合的子类,可以保存到流中或在流中加载,,,,,注:不可使用泛型,当成普通类创建
<%@ page import="cn.itcast.domain.User" %>
<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>el获取数据</title>
</head>
<body>
<%
User user = new User();
user.setName("张三");
user.setAge(23);
user.setBirthday(new Date());
request.setAttribute("u",user);
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add(user);
request.setAttribute("list",list);
Map map = new HashMap();
map.put("sname","李四");
map.put("gender","男");
map.put("user",user);
request.setAttribute("map",map);
%>
<h3>el获取对象中的值</h3>
${requestScope.u}<br>
<%--
* 通过的是对象的属性来获取
* setter或getter方法,去掉set或get,在将剩余部分,首字母变为小写。
* setName --> Name --> name
--%>
${requestScope.u.name}<br>
${u.age}<br>
${u.birthday}<br>
${u.birthday.month}<br>
${u.birStr}<br>
<h3>el获取List值</h3>
${list}<br>
${list[0]}<br>
${list[1]}<br>
${list[10]}<br>
${list[2].name}
<h3>el获取Map值</h3>
${map.gender}<br>
${map["gender"]}<br>
${map.user.name}
</body>
</html>
|
|