<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*"%>
<html>
<body Bgcolor=cyan><FONT size=3>
<%
File f=new File("D:/","A.java");
if(f.exists())
{
f.delete();
}
else
{
f.createNewFile();
}
<%
out.print("File name:"+f.getName());
out.print("File path:"+f.getPath());
%>
</font>
</body>
</html>

解决方案 »

  1.   

    f.createNewFile(); 应该需要抛出异常吧。
      

  2.   

    这段时间在学Java的File对象,所以自己想着做实践.希望高手多多指导.看可不可以再深入一点. 
      

  3.   

    <%@ page contentType="text/html;charset=GB2312" %>
    <%@ page import="java.io.*"%>
    <html>
    <body Bgcolor=cyan><FONT size=3>
    <%
    File f=new File("D:/","A.java");
    if(f.exists())
    {
    f.delete();
    }
    else
    {
    f.createNewFile();
    }
    <%--------去掉或者修改成:%>  <%
    out.print("File name:"+f.getName());
    out.print("File path:"+f.getPath());
    %>
    </font>
    </body>
    </html>
      

  4.   

    <%@ page contentType="text/html;charset=GB2312" %>
    <%@ page import="java.io.*"%>
    <html>
    <body Bgcolor=cyan><FONT size=3>
    <%
    File f=new File("D:/","A.java");
    File dir=new File("D:/","TIANKANGLE");
    if(f.exists()&dir.exists())
    {
    f.delete();
    dir.delete();
    }
    else
    {
    f.createNewFile();
    dir.createNewFile();
    }out.print("File name:"+f.getName());
    out.print("File path:"+f.getPath());
    out.print("文件名:"+dir.getName());
    out.print("路径:"+dir.getPath());
    %>
    </font>
    </body>
    </html>
    这样写出来显示正常:
    File name:A.java File path:D:\A.java File name:TIANKANGLE File path:D:\TIANKANGLE 用什么可以让这段回车到下行.File name:TIANKANGLE File path:D:\TIANKANGLE 
      

  5.   

    out.print("File name:"+f.getName());
    out.print("File path:"+f.getPath());
    <br>
    out.print("文件名:"+dir.getName());
    out.print("路径:"+dir.getPath());这样加的话不行,提示:
    description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 5 in the jsp file: /t5.jsp
    Generated servlet error:
    Syntax error on token(s), misplaced construct(s)
      

  6.   

    out.print("File name:"+f.getName());
    out.print("File path:"+f.getPath() + "<BR>");out.print("文件名:"+dir.getName());
    out.print("路径:"+dir.getPath());
      

  7.   

    <%@ page contentType="text/html;charset=GB2312" %>
    <%@ page import="java.io.*"%>
    <html>
    <body Bgcolor=cyan><FONT size=3>
    <%
    File f=new File("D:/","A.java");
    if(f.exists())
    {
    f.delete();
    }
    else
    {
    f.createNewFile();
    }
    out.println("File name:"+f.getName()+boolean b1=f.delect());
    out.println("File path:"+f.getPath());%>
    <p>文件A.java成功删除了吗?
    <%=b1%></font>
    </body>
    </html>
      

  8.   

    out.println("File name:"+f.getName()+boolean b1=f.delect());
    这样的语方对吗?
      

  9.   

    out.println("File name:"+f.getName()+b1=f.delect());