package readandwrite;
import java
import java
import java
import java
import java
import java
import java
import java
import java
public class ReadAndWrite {
private static BufferedReader br;
private static BufferedWriter bw;
/**
* @param args
* @throws IOException
*
* 兩個問題
*/
public static void main(String[] args) throws IOException {
File dir = new File(
String newPath =
File file
if(!file
file
}
File file[] = dir
for (int i =
if(file[i]
continue;
}
String filename = file[i]
br = new BufferedReader(new InputStreamReader(new FileInputStream(file[i]
File f = new File(newPath+filename)
if(f
f
}
f
FileWriter fw = new FileWriter(f
bw = new BufferedWriter(fw)
if(
String data = ;
while((data = ())!=null)
{
bw
bw
}
} else if(
String data = ;
while((data = ())!=null)
{
bw
bw
}
}
}
}
/*
* 獲取文件擴展名
*/
public static String exn(String filename) {
int k = filename
if(k>
return filename
} else {
return
}
}
/*==============================================解析
/*
* 拆分
* 規則
*/
public static String split(String s) {
String data
String reg =
String[] word = s
ArrayList<String> tag = new ArrayList<String>()
String[] tem = s
// 保存標點符號
for(int i=
{
if(tem[i]
tag
}
}
int k =
for (int i =
String fw = format(word[i])
if(i < tag
data += fw+tag
} else {
data += fw;
}
k = i;
}
if(tag
for (int i = k+
data += tag
}
}
return data;
}
/*
* 駝峰格式子串去大寫
*/
public static String format(String str) {
String reg =
Pattern p = pile(reg)
if(p
return str
}
return str;
}
/*==============================================解析
/*
* 拆分
* 將 組合 id name =
*/
public static String sp
if(ntains(
return split(str)
}
return str;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26132.html