java输出文件

try {
File file = new File("D:\\JB_JCZY_UNIT_INFO.sql");
FileReader fileReader = new FileReader(file);
BufferedReader br = new BufferedReader(fileReader);
StringBuffer sb = new StringBuffer();
String str;
while((str=br.readLine())!=null){
if(" ".equals(str)){
sb.append("\r\n");
}else{
StringTokenizer toKenizer = new StringTokenizer(str,"#");
int num = toKenizer.countTokens();
String[] items = new String[num];
for(int k=0;k items[k] = toKenizer.nextToken();
}
System.out.println(items[0]);
sb.append("update jczy_unit_info set cant='"+items[0].trim()+"',service_code='"+items[53].trim()+"' where unit_id='"+items[1].trim()+"'");
}
}
br.close();
file = new File("D:\\update.sql");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(sb.toString());
bw.close();
} catch (Exception e) {
e.printStackTrace();
}

你可能感兴趣的:(Java)