300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > IOl:从文件夹中找到后缀名为TXT的文件 然后复制到指定的文件夹

IOl:从文件夹中找到后缀名为TXT的文件 然后复制到指定的文件夹

时间:2020-08-24 13:09:37

相关推荐

IOl:从文件夹中找到后缀名为TXT的文件 然后复制到指定的文件夹

/*** 从文件夹中找到后缀名为TXT的文件,然后复制到指定的文件夹* @param args* @throws IOException*/public static void main(String[] args) throws IOException {File file = new File ("C:\\Users\\Administrator\\Desktop\\game2");File file1 = new File ("C:\\Users\\Administrator\\Desktop\\game");copy (file,file1,".txt");}public static void copy(File file,File dec ,String findName) throws IOException {File[] files = file.listFiles ();if(files==null){return;}for (File file1 : files) {if(file1.isDirectory ()){copy (file1,dec,findName);}else if(file1.getName ().endsWith (findName)){InputStream is = new FileInputStream (file1);OutputStream os = new FileOutputStream (dec+"/"+file1.getName ());byte[] arr = new byte[1024*8];int len ;while ((len=is.read(arr))!=-1){os.write (arr);}os.close ();is.close ();}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。