1. package fileReader;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.io.OutputStream;
  12.  
  13. import javax.swing.JOptionPane;
  14.  
  15. public class DemoFilre {
  16. private static String MESSAGE = "";
  17.  
  18. public static void main(String[] args) {
  19. String filePath = System.getProperty("user.home") + "\\Desktop\\aaa.txt";
  20. readTxtFile(filePath);
  21.  
  22. }
  23.  
  24. public static void readTxtFile(String filePath) {
  25. try {
  26. String encoding = "GBK";
  27. File file = new File(filePath);
  28. if (file.isFile() && file.exists()) { // 判断文件是否存在
  29. InputStreamReader read = new InputStreamReader(
  30. new FileInputStream(file), encoding);// 考虑到编码格式
  31. BufferedReader bufferedReader = new BufferedReader(read);
  32. String lineTxt = null;
  33. while ((lineTxt = bufferedReader.readLine()) != null) {
  34. if(lineTxt.startsWith("==")) continue;
  35. if(lineTxt.isEmpty()) continue;
  36. System.out.println("D:\\workspace\\spdbSjptServer\\WebRoot\\" + lineTxt.toString());
  37. // 读文件,copy
  38. copyFile("D:\\workspace\\spdbSjptServer\\WebRoot\\" + lineTxt.toString(), System.getProperty("user.home") + "\\Desktop\\待上线\\" + lineTxt.toString(), true);
  39. }
  40. read.close();
  41. } else {
  42. System.out.println("找不到指定的文件");
  43. }
  44. } catch (Exception e) {
  45. System.out.println("读取文件内容出错");
  46. e.printStackTrace();
  47. }
  48.  
  49. }
  50.  
  51. public static boolean copyFile(String srcFileName, String destFileName,
  52. boolean overlay) {
  53. File srcFile = new File(srcFileName);
  54.  
  55. // 判断源文件是否存在
  56. if (!srcFile.exists()) {
  57. MESSAGE = "源文件:" + srcFileName + "不存在!";
  58. JOptionPane.showMessageDialog(null, MESSAGE);
  59. return false;
  60. } else if (!srcFile.isFile()) {
  61. MESSAGE = "复制文件失败,源文件:" + srcFileName + "不是一个文件!";
  62. JOptionPane.showMessageDialog(null, MESSAGE);
  63. return false;
  64. }
  65.  
  66. // 判断目标文件是否存在
  67. File destFile = new File(destFileName);
  68. if (destFile.exists()) {
  69. // 如果目标文件存在并允许覆盖
  70. if (overlay) {
  71. // 删除已经存在的目标文件,无论目标文件是目录还是单个文件
  72. new File(destFileName).delete();
  73. }
  74. } else {
  75. // 如果目标文件所在目录不存在,则创建目录
  76. if (!destFile.getParentFile().exists()) {
  77. // 目标文件所在目录不存在
  78. if (!destFile.getParentFile().mkdirs()) {
  79. // 复制文件失败:创建目标文件所在目录失败
  80. return false;
  81. }
  82. }
  83. }
  84.  
  85. // 复制文件
  86. int byteread = 0; // 读取的字节数
  87. InputStream in = null;
  88. OutputStream out = null;
  89.  
  90. try {
  91. in = new FileInputStream(srcFile);
  92. out = new FileOutputStream(destFile);
  93. byte[] buffer = new byte[1024];
  94.  
  95. while ((byteread = in.read(buffer)) != -1) {
  96. out.write(buffer, 0, byteread);
  97. }
  98. return true;
  99. } catch (FileNotFoundException e) {
  100. return false;
  101. } catch (IOException e) {
  102. return false;
  103. } finally {
  104. try {
  105. if (out != null)
  106. out.close();
  107. if (in != null)
  108. in.close();
  109. } catch (IOException e) {
  110. e.printStackTrace();
  111. }
  112. }
  113. }
  114. }

项目差异class文件提取-->上线用的更多相关文章

  1. webpack4对第三方库css,项目全局css和vue内联css文件提取到单独的文件(二十二)

    在讲解提取css之前,我们先看下项目的架构如下结构: ### 目录结构如下: demo1 # 工程名 | |--- dist # 打包后生成的目录文件 | |--- node_modules # 所有 ...

  2. 【c++基础】从json文件提取数据

    前言 标注数据导出文件是json格式的,也就是python的dict格式,需要读取标注结果,可以使用c++或者python,本文使用c++实现的. JsonCpp简介 JsonCpp是一种轻量级的数据 ...

  3. 苹果IPSW文件提取软件

    ipsw文件 提取系统文件 方法总结 由于修改运营商文件造成我的有锁4S无法使用移动卡了,在网上苦寻一番还是没有结果,最后萌生了从固件中提取文件的想法,于是便开始在网上搜集资料,最后文件终于提取成功并 ...

  4. [转载]将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,解决办法

    eclipse 代码中文注释乱码 求解决 将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,主要原因就是别人的IDE编码格式和自己的Eclips ...

  5. C#项目打开/保存文件夹/指定类型文件,获取路径

    C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...

  6. 对Android项目中的文件夹进行解释

    对Android项目中的文件夹进行解释: · src:里面存放的是Activity程序,或者是以后的其他组件,在此文件夹之中建立类的时候一定要注意,包名称不能是一级. · gen:此文件夹中的内容是自 ...

  7. VS2012更改项目编译后文件输出目录

    1.现在我的解决方案里有存在两个项目,分别是类库项目ClassLibrary1和控制台项目ConsoleApplication1,默认情况下当解决方案重新生成后,这两个项目所对应的编译后文件分别会存在 ...

  8. git项目添加.gitigore文件

    以前一直没有注意这个文件,最近读到了黄勇的<架构探险>,觉得这个文件还是很有用的. .gitigore文件可以自己配置. 我使用的是书中所用的配置,简洁明了. # Maven # targ ...

  9. 用MT.exe将exe中的manifest文件提取出来和将manifest文件放入exe中

     前一种方法是将manifest文件放入exe中,但是要记得需要在工程中设置 这样的话exe中就不存在manifest了,在debug目录下就会看到相应的manifest文件.后者是将exe中的man ...

随机推荐

  1. 北美IT公司大致分档

    北美IT公司大致分档(from mitbbs.com) 第一档: Uber, Snapchat, Airbnb, Dropbox, Pinterest 第二档:Facebook, LinkedIn, ...

  2. Hibernate框架之入门案例

    今天终于开始学习了三大框架的其中一个框架,Hibernate框架,在这里不去讲Hibernate框架的一些基础概念了,直接切入代码,带大家了解一下Hibernate能干什么, Hibernate的人们 ...

  3. ubutu之jdk安装

    1.jdk下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.解压jdk- ...

  4. 深入理解 CSS3 弹性盒布局模型

    Web 应用的样式设计中,布局是非常重要的一部分.布局用来确定页面上不同组件和元素的尺寸和位置.随着响应式用户界面的流行,Web 应用一般都要求适配不同的设备尺寸和浏览器分辨率.响应式用户界面设计中最 ...

  5. Knockout.Js案例一Introduction

    </strong></p> <p>Last name: <strong data-bind="text:lastName ">tod ...

  6. 【转】CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)

    此种方法很简单.每次都用源码编译,浪费好多时间啊! 同样的网站程序在Linux下运行要比在windows下快出不少,所以决定使用Linux的发行版CentOS ,本文主要讲解在CentOS下使用yum ...

  7. unity3d 安卓IOS推送

    https://github.com/jpush/jpush-unity3d-plugin

  8. BZOJ 3362: [Usaco2004 Feb]Navigation Nightmare 导航噩梦

    Description 给你每个点与相邻点的距离和方向,求两点间的曼哈顿距离. \(n \leqslant 4\times 10^4\) . Sol 加权并查集. 像向量合成一样合并就可以了,找 \( ...

  9. 32 GroupSock(AddressPortLookupTable)——live555源码阅读(四)网络

    32 GroupSock(AddressPortLookupTable)——live555源码阅读(四)网络 32 GroupSock(AddressPortLookupTable)——live555 ...

  10. 有关在线OJ网络AC爬虫

    搜索源码 爬取代码 自动登录 在线提交 判断AC