アットウィキロゴ

p082707

package lib;
 
import java.io.*;
 
public class pro {
 
    String[] data=new String[60000];
    int s,datanumber;
    String[] adr=new String[60000];
    String[] code=new String[60000];
     String[] name=new String[60000];
      String[] city=new String[60000];
       String[] lon=new String[60000];
        String[] lat=new String[60000];
 
    public static void main(String[] args) {
        pro r=new pro();
    }
    pro(){
 
 
        readfile("post.xml","<ksj:address>");
 
 
        for(s=1;s<datanumber+1;s++){
        adr[s]=rev(data[s]);
 
        }
 
 
 
         readfile("post.xml","<ksj:type>");
 
        for(s=1;s<datanumber+1;s++){
        code[s]=rev(data[s]);
        }
 
 
         readfile("post.xml","<ksj:name>");
 
        for(s=1;s<datanumber+1;s++){
        name[s]=rev(data[s]);
        }
 
 
         readfile("post.xml","<ksj:administrativeArea");     
 
        for(s=1;s<datanumber+1;s++){
        city[s]=rev(data[s]);
        }   
 
 
 
 
          readgeo("post.xml");     
 
          String str;
 
           for(s=1;s<datanumber+1;s++){
          str=rev(data[s]);
           str=str.trim();
           String[] x=str.split(" ");
           lon[s]=x[0];
           lat[s]=x[1];
           }
 
        writefile("post.txt");
 
 
    }
    String rev(String str){
    String strx;
    int p1,p2;
        p1=str.indexOf(">");
           p2=str.indexOf("<",p1);
        strx=str.substring(p1+1,p2);
        return strx;
    }
 
    void writefile(String file){ 
 
try{ 
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file))); 
 
for(s=1;s<datanumber;s++){ 
pw.print("<lon>");
pw.print(lon[s]);
pw.print("</lon>");
pw.print("<lat>");
pw.print(lat[s]);
pw.print("</lat>");
pw.print("<name>");
pw.print(name[s]);
pw.print("</name>");
pw.print("<city>");
pw.print(city[s]);
pw.print("</city>");
pw.print("<adr>");
pw.print(adr[s]);
pw.print("</adr>");
pw.print("<code>");
pw.print(code[s]);
pw.println("</code>");
} 
 
System.out.println("ファイルに書きこみました。"); 
pw.close(); 
} catch(IOException ep){ System.out.println("入出力エラーです。"); } 
 
 
} 
 
 
 
 
void readfile(String file,String word){ 
 
String str; 
BufferedReader br;   
int s;
 
 
s=0; 
try { 
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));   
while((str = br.readLine()) != null) {   
if(str.indexOf(word)>-1)s=s+1;
if(str.indexOf(word)>-1)data[s]=str;   
} 
br.close(); 
} catch (IOException e) {System.out.println(e);}   
 
datanumber=s; 
 
} 
 
 
void readgeo(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) {   
if(str.indexOf("<gml:pos>")>-1)s=s+1;
if(str.indexOf("<gml:pos>")>-1)data[s]=str;   
} 
br.close(); 
} catch (IOException e) {System.out.println(e);}   
 
datanumber=s; 
 
} 
 
}
 
最終更新:2015年08月27日 15:44