private static String url = null
private static String user = null
private static String password = null
private static BasicDataSource ds
static{
//读取程序外的.properties 文件
//需要.properties文件的包路径
Properties props = new Properties()
try {
String path ="db.properties"
props.load(
DBUtils.class.getResourceAsStream(path)
)
//properties对象.getProperty("字符串")
driver=props.getProperty("driver")
url=props.getProperty("url")
user=props.getProperty("user")
password=props.getProperty("password")
ds = new BasicDataSource()
ds.setDriverClassName(driver)
ds.setUrl(url)
ds.setUsername(user)
ds.setPassword(password)
Class.forName(driver)
} catch (Exception e) {
e.printStackTrace()
}
}
这是一个JDBC读取配置文件连接数据库的示例代码,供参考!
//看看吧..对你会有帮助public class FilecTest {
public static void main(String args[])
{
File f=new File("c:\\1.txt")
System.out.println(f.isDirectory()) //测试此抽象路径名表示的文件是否是一个目录。
System.out.println(f.getAbsoluteFile()) //返回抽象路径名的绝对路径名形式
System.out.println(f.getAbsolutePath()) //返回抽象路径名的绝对路径名字符串。
System.out.println(f.isAbsolute())//测试此抽象路径名是否为绝对路径名
System.out.println(f.isDirectory())//测试此抽象路径名表示的文件是否是一个目录
long modifyDate = f.lastModified()//得到最后修改日期
if (modifyDate!=0){
System.out.println("\n 最后修改日期: "+new Date(modifyDate))//返回此抽象路径名表示的文件最后一次被修改的时间。
}
System.out.println(new Date(modifyDate))//返回此抽象路径名表示的文件最后一次被修改的时间。
System.out.println(f.length()) //返回由此抽象路径名表示的文件的长度
// System.out.println(f.renameTo(ff)) //重新命名此抽象路径名表示的文件。
}
}