程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-06(4)

MavenCopyJarFile.java

发布于2021-04-18 14:10     阅读(182)     评论(0)     点赞(26)     收藏(1)


 

 

  1. import java.io.BufferedInputStream;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.OutputStream;
  10. /**
  11. * 从maven repository把JAR包全部拷贝出来
  12. *
  13. * @author ZengWenfeng
  14. * @email 117791303@QQ.COM
  15. * @mobile 13805029595
  16. */
  17. public class MavenCopyJarFile
  18. {
  19. public static String PATH_DEST = "d:\\lib";
  20. /**
  21. *
  22. * @author ZengWenfeng
  23. * @email 117791303@QQ.COM
  24. * @param args
  25. */
  26. public static void main(String[] args)
  27. {
  28. File d = new File(PATH_DEST);
  29. d.mkdir();
  30. File f = new File("D:\\repository\\");
  31. File[] arrFile = f.listFiles();
  32. if (arrFile != null && arrFile.length > 0)
  33. {
  34. for (int i = 0; i < arrFile.length; i++)
  35. {
  36. //
  37. File curFile = arrFile[i];
  38. //
  39. next(curFile);
  40. }
  41. }
  42. }
  43. /**
  44. *
  45. * @author ZengWenfeng
  46. * @email 117791303@QQ.COM
  47. * @mobile 13805029595
  48. * @param f
  49. */
  50. public static void next(File f)
  51. {
  52. //
  53. if (f.isDirectory())
  54. {
  55. File[] arrFile = f.listFiles();
  56. //
  57. if (arrFile != null && arrFile.length > 0)
  58. {
  59. for (int i = 0; i < arrFile.length; i++)
  60. {
  61. //
  62. File curFile = arrFile[i];
  63. //
  64. next(curFile);
  65. }
  66. }
  67. }
  68. else
  69. {
  70. String str = f.getAbsolutePath();
  71. // System.out.println(str);
  72. if (str.endsWith(".jar") && !str.endsWith("javadoc.jar") && !str.endsWith("sources.jar"))
  73. {
  74. System.out.println(str);
  75. //
  76. copyFile(f.getPath(), PATH_DEST + File.separator + f.getName());
  77. }
  78. }
  79. }
  80. /**
  81. * 拷贝文件
  82. *
  83. * @author ZengWenfeng
  84. * @email 117791303@QQ.COM
  85. * @mobile 13805029595
  86. * @param pathSrc D:\repository\org\yaml\snakeyaml\1.27\snakeyaml-1.27.jar
  87. * @param pathDest D:\lib\snakeyaml-1.27.jar
  88. */
  89. public static void copyFile(String pathSrc, String pathDest)
  90. {
  91. File src = new File(pathSrc);
  92. File dest = new File(pathDest);
  93. InputStream is = null;
  94. OutputStream out = null;
  95. try
  96. {
  97. is = new BufferedInputStream(new FileInputStream(src));
  98. out = new BufferedOutputStream(new FileOutputStream(dest));
  99. byte[] flush = new byte[1024];
  100. int len = -1;
  101. while ((len = is.read(flush)) != -1)
  102. {
  103. out.write(flush, 0, len);
  104. }
  105. out.flush();
  106. }
  107. catch (FileNotFoundException e)
  108. {
  109. e.printStackTrace();
  110. }
  111. catch (IOException e)
  112. {
  113. e.printStackTrace();
  114. }
  115. finally
  116. {
  117. try
  118. {
  119. is.close();
  120. out.close();
  121. }
  122. catch (IOException e)
  123. {
  124. e.printStackTrace();
  125. }
  126. }
  127. }
  128. }

 



所属网站分类: 技术文章 > 博客

作者:javajava我最强

链接:http://www.javaheidong.com/blog/article/159857/62b0891890d0d5fb1687/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

26 0
收藏该文
已收藏

评论内容:(最多支持255个字符)