概述
package ReadTXT;
//MI Report
import java.io.*;
public class Filedo {
static private String msgName;
//逐行写入文本
public static void main(String[] args) throws IOException{
String filePath = "D://Workspaces//eclipse//workspace//Test//data//MI Report";
File file = new File(filePath);
if(!file.isDirectory()){
readFile(filePath);
}else if (file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filePath + "//" + filelist[i]);
if (!readfile.isDirectory()) {
System.out.println("path=" + readfile.getPath());
System.out.println("absolutepath=" + readfile.getAbsolutePath());
System.out.println("name=" + readfile.getName());
String content = readFile(readfile.getPath());
String newFilePath = filePath + "\" + msgName + ".csv";
writeFile(content, newFilePath);
} else if (readfile.isDirectory()) {
readFile(filePath + "//" + filelist[i]);
}
}
}
}
public static final void writeFile(String str, String filePath) throws IOException {
try {
FileWriter fw = new FileWriter(filePath,true);
String titles = "Institution_name,t" + "Country_code,t" + "Transation,t" + "Counts,t" + "n";
fw.write(titles + str);
fw.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("write failed");
System.exit(-1);
}
}
//逐行读取写入文本
public static final String readFile(String filePath) throws IOException {
String returnMSG = "";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
for (String line = br.readLine(); line != null; line = br.readLine()) {
System.out.println("*****" + line);
if((!line.contains("--"))&&(!line.startsWith("DNS"))){
if(line.startsWith("MSG_name"))
{
msgName = line.substring((line.lastIndexOf("=") + 3),line.lastIndexOf("""));
System.out.println("--------------------------------------------------");
System.out.println(msgName);
//writeFile(msgName + "n");
//test
String titles = "institution_name,t" + "country_code,t" + "transation,t" + "counts,t";
//writeFile(titles + "n");
//returnMSG = "titles + n";
System.out.println(titles);
}else if((!line.contains("="))&&(!line.contains("count"))){
line = line.substring(0, line.length());
/*StringBuffer stdLine = new StringBuffer(line);
stdLine = stdLine.insert(5, ",");
stdLine = stdLine.insert(16, ",");
stdLine = stdLine.insert(22, ",");
stdLine = stdLine.insert(30, ",");
writeFile(stdLine + "n");*/
String strCount,strTranc,strC_C,strINST,stdLine;
strCount = line.substring(0, 9) + ",";
strTranc = line.substring(10, 19) + ",";
strC_C = line.substring(20, 29) + ",";
strINST = line.substring(30, 39) + ",";
stdLine = strINST + strC_C + strTranc +strCount;
//writeFile(stdLine + "n");
//returnMSG = stdLine + "n";
returnMSG += stdLine + "n";
System.out.println(stdLine);
}
}
}
br.close();
System.out.println("===================================================");
System.out.println(returnMSG);
System.out.println("===================================================");
return returnMSG;
}
}
最后
以上就是多情皮卡丘为你收集整理的MI Report的全部内容,希望文章能够帮你解决MI Report所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复