JDK怎么创建文件和目录?

来源:百度知道 编辑:UC知道 时间:2024/06/03 16:59:24
急用。。谢谢

/**
* 保存文件
* @param file
* @param path
* @param fileName
* @return
*/
public static boolean saveFilePath(File file, String path, String fileName) {

try {
if(!path.endsWith("/")){
path += "/";
}
FileOutputStream fos = new FileOutputStream(path + "/" + fileName);
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.flush();
fos.close();
return true;
} catch (IOException e) {
//e.printStackTrace();
return false;
}
}

创建目录
File f1 = new File(path);
if(!f1.isDirectory()){
f1.mkdirs();
}

你去看JDK的API吧。里面都有。