62,616
社区成员
发帖
与我相关
我的任务
分享
<record row="1">
<cell name="bank" column="S">F204H101500000001</cell>
<cell name="serianumber" column="T">GB02447521</cell>
<cell name="amount" column="U">500</cell>
<cell name="risk-state" column="V">1</cell>
<cell name="guarantor1-code" column="W">
</cell>
<cell name="guarantor1-name" column="X">
</cell>
<cell name="guarantor2-code" column="Y">
</cell>
<cell name="guarantor2-name" column="Z">
</cell>
<cell name="industry-code" column="AA">H63</cell>
<cell name="restricted-industry" column="AB">N</cell>
<cell name="expire-date" column="AC">20091224</cell>
</record>
<record row="2">
<cell name="bank" column="S">F204H101500000001</cell>
<cell name="serianumber" column="T">GB02447523</cell>
<cell name="amount" column="U">200</cell>
<cell name="risk-state" column="V">1</cell>
<cell name="guarantor1-code" column="W">
</cell>
<cell name="guarantor1-name" column="X">
</cell>
<cell name="guarantor2-code" column="Y">
</cell>
<cell name="guarantor2-name" column="Z">
</cell>
<cell name="industry-code" column="AA">H63</cell>
<cell name="restricted-industry" column="AB">N</cell>
<cell name="expire-date" column="AC">20091224</cell>
</record>
<record row="3">
<cell name="bank" column="S">F204H101500000001</cell>
<cell name="serianumber" column="T">GB02447515</cell>
<cell name="amount" column="U">400</cell>
<cell name="risk-state" column="V">1</cell>
<cell name="guarantor1-code" column="W">
</cell>
<cell name="guarantor1-name" column="X">
</cell>
<cell name="guarantor2-code" column="Y">
</cell>
<cell name="guarantor2-name" column="Z">
</cell>
<cell name="industry-code" column="AA">H63</cell>
<cell name="restricted-industry" column="AB">N</cell>
<cell name="expire-date" column="AC">20091222</cell>
</record>
import java.io.*;
/**
*
* @author Administrator
*/
public class ReadWriteStr_de {
public static final String UTF_8 = "UTF-8";
/**
* 字符串编码转换的实现方法
* @param str 待转换的字符串
* @param newCharset 目标编码
*/
public static String changeCharset(String str, String newCharset) throws UnsupportedEncodingException {
if(str != null) {
//用默认字符编码解码字符串。与系统相关,中文windows默认为GB2312
byte[] bs = str.getBytes();
return new String(bs, newCharset); //用新的字符编码生成字符串
}
return null;
}
/**
* 字符串编码转换的实现方法
* @param str 待转换的字符串
* @param oldCharset 源字符集
* @param newCharset 目标字符集
*/
public static String changeCharset(String str, String oldCharset, String newCharset) throws UnsupportedEncodingException {
if(str != null) {
//用源字符编码解码字符串
byte[] bs = str.getBytes(oldCharset);
return new String(bs, newCharset);
}
return null;
}
public static String toUTF_8(String str) throws UnsupportedEncodingException {
return ReadWriteStr_de.changeCharset(str, UTF_8);
}
public static int findstr(String str,String findstr){
int i=0;
if(str.indexOf(findstr)>0){
i=str.indexOf(findstr);
}
else {
i=str.length();
}
return i;
}
public static boolean startWithABC(String str){
boolean tf=false;
if(str.startsWith("A")||
str.startsWith("B")||
str.startsWith("C")||
str.startsWith("D")||
str.startsWith("E")||
str.startsWith("F")||
str.startsWith("G")||
str.startsWith("H")||
str.startsWith("I")||
str.startsWith("J")||
str.startsWith("K")||
str.startsWith("L")||
str.startsWith("M")||
str.startsWith("N")||
str.startsWith("O")||
str.startsWith("P")||
str.startsWith("Q")||
str.startsWith("R")||
str.startsWith("S")||
str.startsWith("T")||
str.startsWith("U")||
str.startsWith("V")||
str.startsWith("W")||
str.startsWith("X")||
str.startsWith("Y")||
str.startsWith("Z")
)
{
tf=true;
}
return tf;
}
public static void main(String[] args) throws Exception{
String filePath = "d:/javatest/temp/200910_de_其它支行汇总.xml";
String tmpFile = "d:/javatest/temp/200910_de_其它支行汇总_new.xml";
FileReader myFileR=new FileReader(filePath);
BufferedReader myBufferedReader=new BufferedReader(myFileR);
//FileWriter myFileW=new FileWriter(tmpFile);
//BufferedWriter myBufferedWriter=new BufferedWriter(myFileW);
FileWriter writer=new FileWriter(tmpFile);
BufferedWriter myBufferedWriter=new BufferedWriter(writer);
//System.out.println("test1");
String[] linestr=new String[100000];
int i=0;
String findstr="<cell name=\"identification-code\" column=\"E\">";
String findstr2="</cell>";
String findstr3="<cell name=\"identification-type\" column=\"D\">";
//将文件读入内存
while((linestr[i]=myBufferedReader.readLine())!=null){
i++;
}
i--;
String tmpstr=null;
for(int a=0;a<=i;a++){
//查找到证件号码
if(linestr[a].indexOf(findstr)>0){
//分离出证件号码
tmpstr=linestr[a].substring(linestr[a].indexOf(findstr)+findstr.length(),findstr(linestr[a],findstr2));
//System.out.println(tmpstr);
//如果证件号码以大写字母开始,则把上一行的证件类型改成I
if(startWithABC(tmpstr)){
if(linestr[a-1].indexOf(findstr3)>0){
linestr[a-1]="<cell name=\"identification-type\" column=\"D\">I</cell>";
}
}
}
}
//System.out.println("i="+i);
//int j=i-1;
for(int m=0;m<i;m++){
//System.out.println(linestr[m]);
myBufferedWriter.write(linestr[m]+"\n");
}
myBufferedWriter.flush();
myBufferedWriter.close();
myBufferedReader.close();
myFileR.close();
writer.close();
}
}