Java常用代码
/**
* 创建一个新的文件
* @param relativePath 相对路径
* @param fileName 文件名
* @return
* @throws IOException
*/
public File createFile(String relativePath, String fileName) throws IOException {
String upPath = getFileUploadPath() + relativePath + "\\";
System.out.println("upPath:" + upPath);/////////////////////////////
System.out.println("fileName:" + fileName);/////////////////////////////
String nameWithoutExt = getNameWithoutExtension(fileName);
String ext = getExtension(fileName);
createDirectory(upPath);// 上传目录不存在则创建目录
File newFile = new File(upPath + fileName);
// 若有重名文件则修改名称创建新的文件
for (int counter = 1; newFile.exists(); counter ++) {
fileName = nameWithoutExt + "(" + String.valueOf(counter) + ")." + ext;
newFile = new File(upPath + fileName);
}
newFile.createNewFile();
return newFile;
}
=================================================================================
/**
* 文件的写入 (单行写入)
* @param filePath(文件路径)
* @param fileName(文件名)
* @param args
* @throws IOException
*/
public void writeF
相关文档:
//java.io
---------------------------------------------------------------
/**
* Title: 文件的各种操作
* Copyright: Copyright (c) 2004
* Company: 广东 有限公司
* @author 网络信息部 庆丰
* @version 1.0
*/
p ......
到http://download.csdn.net/source/1781441下载JLDAP.jar文件
验证代码段如下:
DirContext ctx = null;
String account = "aa"; //用户名
String password = "123"; //登录密码
String root = "dc=scut,dc=edu,dc=cn"; // root
Hashtable env = new Hashtable() ......