今天Sailesh那儿有个活想要找出所有cfmail出处的,他用的dreawaver,我用NP++找的慢死,于是我看他那有个xml export,我说把那个给我,他还说这个费劲啊,我想办法克服他不就行了。我的办法就是text processing,我用JAVA呗,我的新宠,可是不会用啊,let's 学!
首先是stream的概念,啥是流?官方解义:An I/O Stream represents an input source or anoutput destination, which means:就是在程序吃进去和吐出来的那串流。联想一下C++, there we go!
然后是Java里面的class,有好多,我先学了bytestream,character stream,区别就是前者是8位读写,后者是Unicode 16位。
最后学了个buffered stream,是因为来回从文件来回太慢,buffer顾名思义把它缓存,加快了。
总结如下,package import同名:
byte stream: FileInputStream / FileOutputStream,
character stream: FileReader / FileWriter,
buffered stream: BufferedReader / BufferedWriter.
另附CODES:
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class test {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new FileReader("test.txt"));
bw = new BufferedWriter(new FileWriter("results.txt"));
String sCurrentLine;;
while ((sCurrentLine = br.readLine()) != null) {
bw.write(processOneLine(sCurrentLine, "mailto:"));
bw.write("\n");
}
} finally {
if (br != null) {
br.close();
}
if (bw != null) {
bw.close();
}
}
}
public static String processOneLine(String line,String target) {
String result = new String();
if (line.contains(target)) {
int begin = line.indexOf(target)+target.length();
int end = begin;
while (end < line.length()) {
if (line.charAt(end) =='\"')
break;
end++;
}
result = line.substring(begin,end);
}
return result;
}
}