码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-03-27 19:25:35      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

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();
        }
        catch(Exception e){
            out.print(e);
        } */
        
        //通过字符输出流写入文件信息
        String str="容我三思";
        char c[]=str.toCharArray();//String强转为Char型
        Writer o=new FileWriter(file,true);
        o.write(c);
        o.flush();
        o.close();
        
     %>
</body>
</html>

 

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

标签:

原文地址:http://www.cnblogs.com/tianhengblogs/p/5326442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!