File
来源:互联网 发布:java messagedigest 编辑:程序博客网 时间:2024/06/10 19:27
Now, I will tell you how to create a file or delete a file. Mabe it very easy for someone, but it indeed difficult for most students who learn java not too long.
import java.io.File;import java.io.IOException;public class FileClass {/** * @author lushun * @param args * @throws IOException */public static void main(String[] args) throws IOException {// The following is to tell you how to create a file.String path = "e:/lushun/weidan/xiaoli";File f = new File(path, "c.txt");if (!f.exists()) {if (!f.getParentFile().exists()) {f.getParentFile().mkdirs();f.createNewFile();} else {f.createNewFile();}}// Calls the function to delete file 'lushun' and other files it// include.File f1 = new File("e:/lushun");// deleteFile(f1);// Returns an array of strings naming the files and directories in the// directory denoted by this abstract pathname.String[] s = f.getParentFile().list();for (int i = 0; i < s.length; i++)System.err.println(s[i]);}public static void deleteFile(File file) {// Delete the whole file including// all directory and normal// file.if (file.isFile()) {file.delete();} else if (file.isDirectory()) {File[] f = file.listFiles();for (int i = 0; i < f.length; i++) {deleteFile(f[i]);}}file.delete();}}
There have a result in the following picture. Do you know which sentence lead to this reslut?
0 0
- File
- file
- File
- file
- File
- File
- file
- file
- file
- File
- File
- file
- file
- File
- FILE
- file
- file
- file
- Android性能优化典范
- BC 61 Numbers
- UESTC1218 2015CCPC DP 0,1背包
- Editplus和Notepad++设置默认编码
- BC 61 Game
- File
- (第二部分)容器和算法——顺序容器
- red hat使用
- JAVA编程中g.drawImage(pict, a, b, 50, 50, this);函数出错
- 国家商用密码(七)在Apache MINA上实现二进制流的SM4编解码器
- java中g.drawImage(pict, a, b, 50, 50, this);函数出错问题
- 国家商用密码(八)在Apache MINA上实现文本流的SM4编解码器
- perldoc用法
- Java环境变量配置