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 ......
网络程序的很大一部分是简单的输入输出,即从一个系统向另一个系统移动字节。字节就是字节,在很大程度上,读服务器发送的数据与读取文件没什么不同;向客户传送数据与写入一个文件也没有什么区别。
Java中输入和输出组织不同于大多数其他语言。它是建立在流(stream)上。不同的基本流类(如java.io.FileInputStream和sun.ne ......
19.1.1. Spring对log4j的几个增强
注意
个人建议都不要使用。
定时刷新log4j.properties,无须重启服务器更新log4j设置。虽然这是个J2EE Best
Practice,但在Spring的JavaDoc里注明了不推荐用于生产环境,因为服务器重启的时候,那条watch thread不会关闭。
将
log4j.properties文件放在WEB-INF/log4j.properti ......