zoukankan      html  css  js  c++  java
  • java获取文件是否文件夹

    package Test;     
    import java.io.File;    
      
    /**  
     * @author yinxm  
     * @version 1.0 2005/06/17  
     *   
     * This class can take file's path and file's name;  
     * you must give the path where you want to take the file.  
     */  
    public class TakeFilePathAndName {    
      
        public static void main(String[] args) {   
            // This is the path where the file's name you want to take.   
            String path = "C://Documents and Settings//yinxm//デスクトップ//TestFile";   
            getFile(path);   
        }   
           
        private static void getFile(String path){   
            // get file list where the path has   
            File file = new File(path);   
            // get the folder list   
            File[] array = file.listFiles();   
              
            for(int i=0;i<array.length;i++){   
                if(array[i].isFile()){   
                    // only take file name   
                    System.out.println("^^^^^" + array[i].getName());   
                    // take file path and name   
                    System.out.println("#####" + array[i]);   
                    // take file path and name   
                    System.out.println("*****" + array[i].getPath());   
                }else if(array[i].isDirectory()){   
                    getFile(array[i].getPath());   
                }   
            }   
        }   
    }  
    

    --转发:https://zhuanlan.zhihu.com/p/150828198
     

  • 相关阅读:
    汉诺塔
    协变和逆变随笔
    NetCore开发第一步 Log4Net日志引入
    插入排序算法
    选择排序算法
    冒泡排序算法
    排序算法
    线性链表
    SAN
    SAM -- Chap 8 提升方法 自我梳理
  • 原文地址:https://www.cnblogs.com/xyyou/p/15624000.html
Copyright © 2011-2022 走看看