package kube;
import java.io.*;
public class pro {
String[] data=new String[600000];
int s,datanumber;
String[] code=new String[600000];
String[] line=new String[600000];
String[] name=new String[600000];
String[] com=new String[600000];
String[] v1=new String[600000];
String[] v2=new String[600000];
String[] v3=new String[600000];
String[] v4=new String[600000];
int number;
String[] geo=new String[600000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readx("data.xml");
String c1="<ksj:station xlink:href=";
String s1="<ksj:stationName>";
String s2="<ksj:administrationCompany>";
String s3="<ksj:routeName>";
String nv1="<ksj:passengers2011>";
String nv2="<ksj:passengers2012>";
String nv3="<ksj:passengers2013>";
String nv4="<ksj:passengers2014>";
int sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf(c1)>-1)sx=sx+1;
if(data[s].indexOf(c1)>-1)code[sx]=data[s];
if(data[s].indexOf(s1)>-1)name[sx]=data[s];
if(data[s].indexOf(s2)>-1)com[sx]=data[s];
if(data[s].indexOf(s3)>-1)line[sx]=data[s];
if(data[s].indexOf(nv1)>-1)v1[sx]=data[s];
if(data[s].indexOf(nv2)>-1)v2[sx]=data[s];
if(data[s].indexOf(nv3)>-1)v3[sx]=data[s];
if(data[s].indexOf(nv4)>-1)v4[sx]=data[s];
}
number=sx;
for(s=1;s<number+1;s++){
int p1=v1[s].indexOf(">");
int p2=v1[s].indexOf("<",p1);
v1[s]=v1[s].substring(p1+1,p2);
p1=v2[s].indexOf(">");
p2=v2[s].indexOf("<",p1);
v2[s]=v2[s].substring(p1+1,p2);
p1=v3[s].indexOf(">");
p2=v3[s].indexOf("<",p1);
v3[s]=v3[s].substring(p1+1,p2);
p1=v4[s].indexOf(">");
p2=v4[s].indexOf("<",p1);
v4[s]=v4[s].substring(p1+1,p2);
System.out.println(v1[s]);
}
for(s=1;s<number+1;s++){
int p1=name[s].indexOf(">");
int p2=name[s].indexOf("<",p1);
name[s]=name[s].substring(p1+1,p2);
p1=com[s].indexOf(">");
p2=com[s].indexOf("<",p1);
com[s]=com[s].substring(p1+1,p2);
p1=line[s].indexOf(">");
p2=line[s].indexOf("<",p1);
line[s]=line[s].substring(p1+1,p2);
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("<gml:posList>")>-1)sx=sx+1;
if(data[s].indexOf("<gml:posList>")>-1)geo[sx]=data[s+1];
}
for(s=1;s<number+1;s++){
geo[s]=geo[s].trim();
geo[s]=geo[s].replace(" ",",");
}
writexml("ren.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.print(name[s]);
pw.print(",");
pw.print(line[s]);
pw.print(",");
pw.print(com[s]);
pw.print(",");
pw.print(geo[s]);
pw.print(",");
pw.print(v1[s]);
pw.print(",");
pw.print(v2[s]);
pw.print(",");
pw.print(v3[s]);
pw.print(",");
pw.println(v4[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2017年03月09日 09:04