Java Programming 【replace tool】
常常需要递归的替换文件内容,如最近我想写了个jEdit插件,jEdit提供了一个插件模板,我只要全部替换一下就成了我自己的工程。在linux下,这好办,shell来搞定,但在Windows下或者不熟悉shell就得想点其他办法来办了,EditPlus可以,UE也可以,不过不太方便的是文件名不好替换,以前给自己写过一个小工具来成批改MP3的名字,后来发现用处蛮大,今天又有新要求了,我就写了MiniTool来完成这一MiniCase。没写UI,因为我自己的系统是RHEL5,喜欢命令行来操作。
Here is the running img by Hypersnap 5.
Here is the code. Just there are two Java files.
package com.jonsenelizee.replace;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Stack;
public class FormattingPrintWriter extends PrintWriter
{
private static final String NEWLINE = System.getProperty("line.separator", "\r\n");
// Standard tab settings
private static final int[] STD_TABS = { 9, 17, 25, 33, 41, 49, 57, 65, 73, 81 };
private boolean _autoFlush;
private int[] _tabs = STD_TABS;
@SuppressWarnings("unchecked")
private Stack _stack = new Stack();
private int _indent;
private int _pos;
/**
* Returns a string consisting of the specified number of spaces.
*
* @return The requested whitespace string.
*/
private static String spaces(int n)
{
char[] ca = new char[n];
for (int i = 0; i < n; i++)
ca[i] = ' ';
return new String(ca, 0, ca.length);
}
/**
* Constructs a new FormattingPrintWriter, without automatic line
* flushing.
*
* @param out
* A character-output stream.
*/
public FormattingPrintWriter(Writer out)
{
super(out);
}
/**
* Constructs a new FormattingPrintWriter.
*
* @param out
* A character-output stream.
* @param autoFlush
* If <code>true</code>, the println() methods will flush
* the output buffer.
*/
public Formattin
相关文档:
package arrays.myArray;
public class MyArrayList {
private Object[] arrObj = new Object[3];
private int size = 0;
// 长度
public int size() {
return size;
}
// insert
public void add(Object obj) {
add(size,obj);
&nb ......
package floatt;
public class Go {
public static int i = 0;
public static void main(String[] args){
calc("", 5);
System.out.println("总共有"+i+"种走法~");
}
//上楼梯每次只需一步或者两步,有多少走法
public static void calc(String lo ......
package game;
public class JieCeng {
public static void main(String[] args){
System.out.println(fun(10));
}
public static int fun(int n){
if(1==n)
return 1;
System.out.println( n * fun(n-1));
return ......
package game;
public class Money {
public static void main(String[] args) {
fun("", 10);
System.out.println("总共算法:" + i);
}
// 10元钱的组成,1,2,5任意组合
public static int i = 1;
public static void fun(String log, int n) {
......
Java 里面0x开头的数值为16进制的
0xf0 = 15*16 = 240;
//简单算,好比十进制60 = 6 *10 = 60;
int i = 0xf0;
就相当于
int i = ......