`
samsongbest
  • 浏览: 162308 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

change package and import

    博客分类:
  • Java
 
阅读更多

package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileUtil {

    private String endFix = ".java";
    private String tempFile = "C:/tempFile.txt";
    private String packageStr = "package";
    private String importStr = "import";
   
   
   
    public void changePackageAndImport(String path) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(path));
        BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
        String str1 = "";
        str1 = br.readLine();
       
            while(str1!=null) {
//                if(str1.startsWith(packageStr)) {
//                    str1 = str1.replace("package ", "package sam.");
//                    bw.write(str1);
//                    bw.newLine();
//                   
//                    if(path.contains("F:/Root/MyLife/workspace/Java官方类学习/src/java/util")) {
//                    bw.write("import java.util.Iterator;");
//                    bw.newLine();   
//                    }
//                } else if(str1.startsWith(importStr)) {
//                                       
//                    str1 = str1.replace("import ", "import sam.");
//                    bw.write(str1);
//                    bw.newLine();
//                } else
                if(str1.contains("(java.io.ObjectOutputStream")) {
                    str1 = str1.replace("(java.io.ObjectOutputStream", "(sam.java.io.ObjectOutputStream");
                    bw.write(str1);
                    bw.newLine();
                }  else if(str1.contains("(java.io.ObjectInputStream")) {
                    str1 = str1.replace("(java.io.ObjectInputStream", "(sam.java.io.ObjectInputStream");
                    bw.write(str1);
                    bw.newLine();
                }  else if(str1.contains("throws java.io.IOException")) {
                    str1 = str1.replace("throws java.io.IOException", "throws sam.java.io.IOException");
                    bw.write(str1);
                    bw.newLine();
                }  else if(str1.contains("throw new java.io.StreamCorruptedException")) {
                    str1 = str1.replace("throw new java.io.StreamCorruptedException", "throw new sam.java.io.StreamCorruptedException");
                    bw.write(str1);
                    bw.newLine();
                }
               
               
               
                else {
                    bw.write(str1);
                    bw.newLine();
                }
           
               
               
               
                str1 = br.readLine();
           
       
           
        }
        bw.close();
        br.close();
       
         br = new BufferedReader(new FileReader(tempFile));
         bw = new BufferedWriter(new FileWriter(path));
       
         str1 = br.readLine();
         while(str1!=null) {
                bw.write(str1);
                bw.newLine();
                 str1 = br.readLine();
         }
            bw.close();
            br.close();
       
    }
   
    public void parsePathOrFile(String path) throws IOException {
        System.out.println(path);
        if(path.equals("C:/MyCitiLife/LearnPlan/JDK/java/awt/font")) {
            int ss = 0;
        }
       
        File[] file = new File(path).listFiles();
        if(file!=null && file.length!=0) {
            for(int i = 0; i< file.length; i++) {
               
                if(file[i].getName().endsWith(endFix)) {
                    changePackageAndImport(path.concat("/".concat(file[i].getName())));
                } else {
                    parsePathOrFile(path.concat("/".concat(file[i].getName())));
                }
               
            }
        }
       
   
    }
   
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        FileUtil FileUtil = new FileUtil();
        FileUtil.parsePathOrFile("F:/Root/MyLife/workspace/Java官方类学习/src");
    }

}

分享到:
评论

相关推荐

    Final IK 1.9.unitypackage

    For the full history of release notes, see FinalIK Change Log.pdf in the package. Upgrade Guide - MAKE A BACKUP! Open a new scene, delete “Plugins/RootMotion” and reimport. Also reimport ...

    FastReport Package Simplification Management Toolkit

    Step1: Execute recompile.exe to generate specified version related folder and files (Recompile all package first, then Change Language to Chinese or othor one). step2: Execute @DelUnUsedFiles.bat to ...

    java课程设计日历源码

    import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.table.*; public class MyCalendar extends JApplet { public static class CalendarTable extends JTable ...

    Final IK 最新版2.1

    For the full history of release notes, see FinalIK Change Log.pdf in the package. Upgrade Guide - MAKE A BACKUP! Open a new scene, delete “Plugins/RootMotion” and reimport. Also reimport ...

    libxl-win-3.8.4.zip

    LibXL is a library for direct reading and writing Excel files. ... changelog.txt change log libxl.url link to home page license.txt end-user license agreement readme.txt this file

    Polygonal Fantasy Pack v1.3

    Please download and import them into your project. 1) Post Processing Stack 2) Cinemachine 3) Unity's Standard assets &gt; Character 3D files are in FBX and texture files are in PSD in the package. ...

    Embedded Browser 3.0.0.unitypackage

    Product Page | Unity Asset Store | Changelog | Get Help Documentation for ZFBrowser v3.0.0. Uses CEF 74.1.19+gb62bacf+chromium-74.0.3729.157 / Chromium 74.0.3729.157. Copyright © 2015-2019 Zen ...

    Advanced+PlayerPrefs+Window+v1.8.2.unitypackage

    It reads all your PlayerPrefs and presents them in such a way you can create, change, delete and save them with one click. You no longer need to code to find out what the current state of your ...

    FastReport企业版源代码6.6.17 支持10.4+ FastReport 简化管理工具2.0

    Step1: Execute recompile.exe to generate specified version related folder and files (Recompile all package first, then Change Language to Chinese or othor one). step2: Execute @DelUnUsedFiles.bat to ...

    UniWebView+3.unitypackage.zip

    You could find step-by-step guides on how to import UniWebView to your project, as well as some basic usage of this asset. You could also find a full script reference on the same site in this page: ...

    gochange:用于与 Change.org API 交互的 Go 包

    com / judrov / gochange用法#####导入package gochange import "github.com/judrov/gochange" #####设置配置参数 // sets API keyparams [ "API_KEY" ] = "my_api_key"// sets secret tokenparams [ "SECRET" ] = ...

    python3.6.5参考手册 chm

    PEP 371: The multiprocessing Package PEP 3101: Advanced String Formatting PEP 3105: print As a Function PEP 3110: Exception-Handling Changes PEP 3112: Byte Literals PEP 3116: New I/O Library PEP...

    JAVA特效之弹出渐变窗口

    package myClass; /* * 淡入淡出窗口,淡出时,如果鼠标移进去了,则中止渐变。 * gradual change Frame */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event....

    UE(官方下载)

    Did you know that you can not only change what is on UltraEdit's toolbars, you can also change the icon used, as well as create your own custom toolbars and tools? File tabs Understand how file tabs ...

    EhLib5.0.13 最新的ehlib源码

    Allows to import data from Text and internal formats. Can sort data in various dataset's. Can filter data in various dataset's. When DBGridEh is connected to DataSet of TMemTable type it allows: ...

    Infinity Science – Software Engineering and Testing.pdf

    9.3 Change-Control Process 197 9.4 Software-Version Control 199 9.5 Software-Configuration Management 200 9.6 Need for Maintenance 202 9.7 Categories of Maintenance 203 9.8 Maintenance ...

    AS3.0 TLFTextField 组件库

    import flashx.textLayout.events.StatusChangeEvent; /** * 使用 TLFTextField 类创建使用文本布局框架 (TLF) 的高级文本显示功能的文本字段。 * TLFTextField 对象与 TextField 对象类似,但 TLFTextField...

    pdfbox-app-1.8.13.jar

    package com.lewei.test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import org.apache.pdfbox....

    操作excel库downkr.com_LibXL

    changelog.txt change log libxl.url link to home page license.txt end-user license agreement readme.txt this file Using library: 1. Microsoft Visual C++ - add include directory in your ...

Global site tag (gtag.js) - Google Analytics