• java_IO_1


    public class DirStudy {
        public static void main(String[] args) {
            File file = new File("F:/EclipseWorkspace/Java300/temp/test");
            //mkdir 父目录中又不存在的就创建失败  若已存在也创建失败  
            boolean flag = file.mkdir();
            System.out.println(flag);
            //mkdirs 会将文件链中不存在的目录都拿创建  推荐使用mkdirs
            flag = file.mkdirs();
            System.out.println(flag);
        }
    }


    
    

    false
    true

    File file = new File("F:/EclipseWorkspace/Java300");
            //返回该目录下的文件或目录的字符串名称  只返回一层
            String[] subString  = file.list();
            for(String temp:subString) {
                System.out.println(temp);
            }
            
            File[] subFile  = file.listFiles();
            for(File temp:subFile) {
                System.out.println(temp.getPath());
            }

    
    

    .classpath
    .project
    .settings
    bin
    src
    temp
    F:EclipseWorkspaceJava300.classpath
    F:EclipseWorkspaceJava300.project
    F:EclipseWorkspaceJava300.settings
    F:EclipseWorkspaceJava300in
    F:EclipseWorkspaceJava300src
    F:EclipseWorkspaceJava300 emp


    递归打印目录下所有内容:

    public static void printPath(File file, int deep) {
            for (int i = 0; i < deep; i++) {
                System.out.print("-");
            }
            System.out.println(file.getAbsolutePath());
            if (file == null || !file.exists()) {
                return;
            } else if (file.isDirectory()) {
                File[] temp = file.listFiles();
                for (File t : temp) {
                    printPath(t, deep + 1);
                }
            }
        }

    输出:

    F:EclipseWorkspaceJava300
    -F:EclipseWorkspaceJava300.classpath
    -F:EclipseWorkspaceJava300.project
    -F:EclipseWorkspaceJava300.settings
    --F:EclipseWorkspaceJava300.settingsorg.eclipse.jdt.core.prefs
    -F:EclipseWorkspaceJava300in
    --F:EclipseWorkspaceJava300inioStudy
    ---F:EclipseWorkspaceJava300inioStudyDirStudy.class
    ---F:EclipseWorkspaceJava300inioStudyIOstudy1.class
    --F:EclipseWorkspaceJava300in	est
    ---F:EclipseWorkspaceJava300in	eststringTest
    ----F:EclipseWorkspaceJava300in	eststringTestArrayCopy1.class
    ----F:EclipseWorkspaceJava300in	eststringTestMyArrayList.class
    ----F:EclipseWorkspaceJava300in	eststringTestMyHashMap.class
    ----F:EclipseWorkspaceJava300in	eststringTestNode.class
    ----F:EclipseWorkspaceJava300in	eststringTestTestBubbleSort.class
    ----F:EclipseWorkspaceJava300in	eststringTestTestCollection.class
    ----F:EclipseWorkspaceJava300in	eststringTestTestString.class
    -F:EclipseWorkspaceJava300src
    --F:EclipseWorkspaceJava300srcioStudy
    ---F:EclipseWorkspaceJava300srcioStudyDirStudy.java
    ---F:EclipseWorkspaceJava300srcioStudyIOstudy1.java
    --F:EclipseWorkspaceJava300src	est
    ---F:EclipseWorkspaceJava300src	eststringTest
    ----F:EclipseWorkspaceJava300src	eststringTestArrayCopy1.java
    ----F:EclipseWorkspaceJava300src	eststringTestMyArrayList.java
    ----F:EclipseWorkspaceJava300src	eststringTestMyHashMap.java
    ----F:EclipseWorkspaceJava300src	eststringTestTestBubbleSort.java
    ----F:EclipseWorkspaceJava300src	eststringTestTestCollection.java
    ----F:EclipseWorkspaceJava300src	eststringTestTestString.java
    -F:EclipseWorkspaceJava300	emp
    --F:EclipseWorkspaceJava300	emp	est
    View Code

    字节到字符是解码(decode),字符到字节是编码(encode)。

  • 相关阅读:
    WINXP下安装IIS+PHP5+MySQL5 +Apache
    centos下配置apache+php+mysql!
    在C#中如何调用记事本
    使用c#捕获windows的关机事件(转载)
    C# WinForm中DataGrid列设置(转载)
    软件开发五要五不要原则
    ASP.NET2.0中将文件上传到数据库(转载)
    如何用C#和ADO.NET建立一个数据绑定网格(转载)
    SQL基础:常用SQL语句详解
    什么是极端编程?
  • 原文地址:https://www.cnblogs.com/ustc-anmin/p/10945877.html
Copyright © 2020-2023  润新知