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>