MyEclipse------快速写入内容到指定目录下的文件(字节输出流)

时间:2021-09-02 11:49:14

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();
        }
        byte b[]="Hello World".getBytes();
        try{
            //true:从文件末尾写入数据    false:删除之前的内容,从新写入数据(默认值)
            OutputStream o=new FileOutputStream(file,true);
            o.write(b);
            o.close();
        }
        catch(IOException e){
            out.print(e);
        }
        
     %>
</body>
</html>