package bou;
import tool.*;
import java.io.*;
public class pro {
int s,datanumber;
String[] code=new String[6000];
String[] credit=new String[6000];
String[] data=new String[6000];
String[][] v=new String[500][200];
String[] bus=new String[6000];
String[] delta=new String[6000];
int number;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
String urlx="http://www.customs.go.jp/toukei/suii/html/data/d51ma.csv";
getdata sub=new getdata();
sub.makedata(urlx,"SJIS");
data=sub.data;
datanumber=sub.datanumber;
int sx;
number=0;
for(s=1;s<datanumber+1;s++){
data[s]=rev_csv(data[s]);
String[] x=data[s].split(",");
for(sx=0;sx<200;sx++){
v[s][sx]="";
}
for(sx=0;sx<x.length;sx++){
v[s][sx]=x[sx];
}
number=x.length;
}
for(s=0;s<number;s++){
code[s]=v[5][s];
credit[s]=v[4][s];
bus[s]=v[3][s];
delta[s]=v[6][s];
}
for(s=1;s<number;s++){
if(credit[s].length()<1)credit[s]=credit[s-1];
if(bus[s].length()<1)bus[s]=bus[s-1];
}
writecsv("ren.csv");
}
void writecsv(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.print("y");
for(sx=1;sx<number;sx++){
if(delta[sx].indexOf("金額")>-1){
pw.print(",");
pw.print(credit[sx]);
}
}
pw.println("");
for(s=8;s<datanumber+1;s++){
pw.print(v[s][0]);
for(sx=1;sx<number;sx++){
if(delta[sx].indexOf("金額")>-1){
pw.print(",");
pw.print(v[s][sx]);
}
}
pw.println("");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String rev_csv(String str){
String str5=str;
int px=str5.indexOf("\"");
while(px>-1){
str5=change(str5);
px=str5.indexOf("\"");
}
return str5;
}
String change(String str){
int p1=str.indexOf("\"");
int p2=str.indexOf("\"",p1+1);
String str1=str.substring(0,p1);
String str2=str.substring(p1+1,p2);
String str3=str.substring(p2+1,str.length());
str2=str2.replace(",","");
return str1+str2+str3;
}
}
最終更新:2016年06月08日 13:48