网站开发公司报价电话营销技巧和营销方法
因工作需要,更新一些文件到服务器上的时候很是麻烦。需要一个个文件更新,要一个个文件的相对路径要先列出来。 为了省点事,就写个工具类来自己生成文件相对路径列表。 当然不完美,但已经够我用了,当然也可以加过滤器什么的,视具体需要,我这里不需要,就没实现了哈。 只要提供项目文件所在的文件夹目录就可以了。 生成后,一次性可以去把前面不需要的绝对路径替换掉,程序就不实现了。嫌麻烦,哈哈。 昨天的有些地方没考虑好,当然是对我而言,我的还需要把所有目录下的文件复制到一个目录下来。这里再做一个补充,源文件不贴出来鸟,第二个附件就是的。 也够晕的,时间一长,自己忘了,居然把第二个附件删除了。哪位下载了的,能把源代码贴一下么。 package com.filepath.demo; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FilePathTool { private static String path=""; public static void setPath(String pathname){ path=pathname; outFilePath(); } public static void outFilePath(){ try { File file=new File(path); if(!file.exists()){ throw new Exception("当前目录不存在!"); } if(!file.isDirectory()){ throw new Exception("请提供一个文件目录!"); } File outfile=new File(path+"\\修改文件路径 .txt"); outfile.createNewFile(); FileWriter fos = new java.io.FileWriter(outfile); readFilePath(file,fos); fos.flush(); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void readFilePath(File filepath,FileWriter br)throws Exception{ String fpath=""; File[] list=filepath.listFiles(); for(File file:list){ if(file.isFile()){ fpath=file.getAbsolutePath().replaceFirst(path, " "); br.write(fpath+"\n"); } if(file.isDirectory()){ readFilePath(file,br); } } } public static void main(String[] args){ System.out.println("开始生成文件路径输出文件。。"); String filedir="D:/test"; FilePathTool.setPath(filedir); System.out.println("完成生成文件路径输出文件。。"); } }