`
samsongbest
  • 浏览: 171370 次
  • 性别: 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: ...

    Aerospike 客户端 Go.zip

    Aerospike 客户端 GoAerospike Go ...package mainimport ( "fmt" aero "github.com/aerospike/aerospike-client-go/v7")// This is only for this example.// Please handle errors properly.func panicOnError(err

    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...

    select angular package

    import { NgSelectModule } from '@ng-select/ng-select'; @NgModule({ imports: [NgSelectModule], // ... }) export class AppModule { } ``` 接着,在HTML模板中,使用`&lt;ng-select&gt;`标签来创建组件,并根据...

    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: ...

Global site tag (gtag.js) - Google Analytics