您的位置:首页 > 编程语言 > Java开发

MyEclipse------文件字符输入,输出流读写信息

2016-03-27 18:47 525 查看
other.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@page import="java.io.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'other.jsp' starting page</title>
</head>

<body>
<%
File file=new File("C:\\Users\\X550V\\Desktop","cc.txt");
if(!file.exists()){
file.createNewFile();
}

//通过字符输入流读取文件信息
/* char c[]=new char[1];
Reader in=new FileReader(file);
try{
int n=-1;
while((n=in.read(c,0,1))!=-1){
String str=new String(c,0,1);
out.print(str);
}
in.close();
out.print("读取数据成功");
}
catch(Exception e){
out.print(e);
} */

//通过字符输出流写入文件信息
String str="容我三思";
char c[]=str.toCharArray();//String强转为Char型
try{
Writer o=new FileWriter(file,true);
o.write(c);
o.flush();
o.close();
out.print("写入数据成功");
}
catch(IOException e){
out.print(e);
}
%>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: