MyEclipse------File类的各种方法

时间:2023-03-09 04:49:42
MyEclipse------File类的各种方法

usingFile.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 'usingFile.jsp' starting page</title>
</head> <body>
<!-- String thePath=request.getRealPath("");作用:获取取得你当前运行文件在服务器上的绝对路径 -->
<%
//path=request.getRealPath("");
//out.println(path);
//String pathe=request.getRealPath("/");
//out.print(pathe);
%>
<br>
<%
String thePath=request.getRealPath("")+"\\file";
out.print(thePath+"<br>");
File dir=new File(thePath);
File myFile=new File(thePath,"usingFile.jsp");
File notExitFile=new File(thePath,"file.txt");
out.print("目录"+thePath+"是否存在: "+dir.exists()+"<br><br>");
out.print("文件"+thePath+"\\usingFile.jsp是否存在: "+myFile.exists()+"<br><br>");
out.print("文件"+thePath+"\\file.txt是否存在: "+notExitFile.exists()+"<br><br>");
out.print("文件"+thePath+"\\usingFile.jsp是否可读: "+myFile.canRead()+"<br><br>");
out.print("文件"+thePath+"\\usingFile.jsp是否可写: "+myFile.canWrite()+"<br>");
%>
</body>
</html>