比如JSP中文件建立与删除:只写出JSP代码
<%@ page contentType="text/html;charset=GB2312" import="java.io.*"%><%
String path=request.getRealPath(".");
File f=new File(path,"File.txt");//建立目前目录下的File.txt的File对象
if(f.exists()) //检查是否存在
{
f.delete();//存在则删除之
out.println(path+"\File.txt");
%>
存在,已完成删除
<%
}
else
{
f.creatNewFile();
out.println(path+"\File.txt");
%>
不存在,已完成建立
<%
}
%>
<%@ page contentType="text/html;charset=GB2312" import="java.io.*"%><%
String path=request.getRealPath(".");
File f=new File(path,"File.txt");//建立目前目录下的File.txt的File对象
if(f.exists()) //检查是否存在
{
f.delete();//存在则删除之
out.println(path+"\File.txt");
%>
存在,已完成删除
<%
}
else
{
f.creatNewFile();
out.println(path+"\File.txt");
%>
不存在,已完成建立
<%
}
%>
解决方案 »
- 初学Java,做了一个练习软件。出现了空指针错问,请大家看看,谢谢
- 分页查询如何做缓存的问题
- 类型强制转换问题:Blob转换成SerializableBlob
- JInternalFrame难道在公用一块内存?? 急切求助ing
- 50分求..WEB上..JavaScript与Applet的互操作..
- java如何使用函数返回多个函数值?求高手知道啊
- JAVA提高~
- 用socket及java.net.*下的相关类与方法可以具体做些什么样的实例系统?请大虾指明一下方向!!
- Applet问题
- 计算星期一?
- 紧急求助!!!JNI调用vc编写的dll,在javah生成的.h对应的.cpp中如何定义全局变量??
- 构造函数的问题
我希望能够使用JDBC读取数据库类型的文件
还是谢谢你 ^_^
import java.sql.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;class AccessDBTest
{
public static void main(String args[])
{
JFrame frame=new AccessDBTestFrame();
frame.show();
}
}class AccessDBTestFrame extends JFrame
{
AccessDBTestFrame()
{
setTitle("ViewDB");
setSize(400,300);
readTree();
JTree tree=new JTree(root);
}
public static Connection getConnection()
throws SQLException
{
System.setProperty("jdbc.drivers","sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+"AccessDB.mdb";
return DriverManager.getConnection(url,"","");
}
public void readTree()
{
try
{
conn=getConnection();
stat=conn.createStatement();
//setup tree model root
root=new DefaultMutableTreeNode("Books");
ResultSet rs=stat.executeQuery("SELECT Name FROM Publishers");
while(rs.next()){
DefaultMutableTreeNode node=new DefaultMutableTreeNode(rs.getString(1));
root.add(node);
}
stat.close();
conn.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,ex);
}
}
private Connection conn;
private Statement stat;
private DefaultMutableTreeNode root;
}