273286078

导航

 

java实现将指定文件夹里所有文件路径输出到指定文件作为参数化文件给lr脚本使用

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class GetFileName {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in ));
          //java.io.InputStreamReader继承了Reader类
        String read = null;
        System.out.print("输入文件夹:");
        read = br.readLine();
        
        BufferedReader br01 = new BufferedReader(new InputStreamReader(System.in ));
          //java.io.InputStreamReader继承了Reader类
        System.out.print("输出的文件:");
        String write = br.readLine();
    
        FileOutputStream fos = new FileOutputStream(write);
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        
        File f = new File(read);
        String dir = f.getAbsolutePath();
        if(f.isDirectory())
        {
            String[] ss = f.list();        
            for(String s:ss)
            {
                bw.write(dir+"\\"+s);
                bw.newLine();
            }
        }
        bw.flush();
        bw.close();
    }
}

 

posted on 2017-11-01 12:32  273286078  阅读(494)  评论(0编辑  收藏  举报