package line;
import java.io.*;
public class Line {
int datanumber,number,articlenumber;
String[] data=new String[500000];
int s;
String[] count=new String[500000];
String[] name=new String[500000];
String[] line=new String[500000];
String[] com=new String[500000];
public static void main(String[] args) {
Line t=new Line();
}
Line(){
readfile("data.xml");
int sx;
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("passengers2012")>-1)sx=sx+1;
if(data[s].indexOf("passengers2012")>-1)count[sx]=data[s];
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("stationName")>-1)sx=sx+1;
if(data[s].indexOf("stationName")>-1)name[sx]=data[s];
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("routeName")>-1)sx=sx+1;
if(data[s].indexOf("routeName")>-1)line[sx]=data[s];
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("routeName")>-1)sx=sx+1;
if(data[s].indexOf("routeName")>-1)line[sx]=data[s];
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("administrationCompany")>-1)sx=sx+1;
if(data[s].indexOf("administrationCompany")>-1)com[sx]=data[s];
}
number=sx;
for(s=1;s<number+1;s++){
name[s]=rev(name[s]);
com[s]=rev(com[s]);
line[s]=rev(line[s]);
count[s]=rev(count[s]);
}
writefile("ren.txt");
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.print("<name>");
pw.print(name[s]);
pw.print("</name>");
pw.print("<line>");
pw.print(line[s]);
pw.print("</line>");
pw.print("<com>");
pw.print(com[s]);
pw.print("</com>");
pw.print("<value>");
pw.print(count[s]);
pw.println("</value>");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String rev(String str){
int p1,p2;
p1=str.indexOf(">");
p2=str.indexOf("<",p1);
String strx=str.substring(p1+1,p2);
return strx;
}
void readfile(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;
}
}
最終更新:2015年04月04日 08:14