アットウィキロゴ

電力

package fd;
 
import tool.catchword;
import tool.readfile;
import java.io.*;
 
 
public class pro {
 
   int s,datanumber;
  String[] data=new String[5000];
  String[] credit=new String[5000];
  String[] year=new String[5000];
  String[] month=new String[5000];
  String[] com=new String[5000];  
  String[] index=new String[5000];
  String[] v=new String[5000];
 
  String[] year_p=new String[5000];
  String[] month_p=new String[5000];
  String[] com_p=new String[5000]; 
   String[] credit_p=new String[5000];
   String[] index_p=new String[5000];
    String[] vs=new String[5000];
 
    public static void main(String[] args) {
        pro test=new pro();
    }
    pro(){
 
 
        int tr;
 
        for(tr=1;tr<135;tr++){
 
         readfile sub7=new readfile();
        sub7.makedata("gdata/"+tr+".txt","UTF-8");
        data=sub7.data;
        datanumber=sub7.datanumber; 
 
 
        for(s=1;s<datanumber+1;s++){
 
       catchword sub2=new catchword();
       credit[s]=sub2.makedata(data[s],"credit");
       com[s]=sub2.makedata(data[s],"com");
       index[s]=sub2.makedata(data[s],"index");
       String str=sub2.makedata(data[s],"date");
       v[s]=sub2.makedata(data[s],"value");
       int p1=str.indexOf("平成");
       int p2=str.indexOf("年");
       int p3=str.indexOf("月");
       year[s]="0";
       month[s]="0";
       if(p3>-1)year[s]=str.substring(p1+2,p2);
        if(p3>-1)month[s]=str.substring(p2+1,p3);   
        }
 
        int z,sx;
        sx=0;
         for(s=1;s<datanumber+1;s++){
         z=0;
         if(index[s].indexOf("電灯計")>-1)z=1;
         if(index[s].indexOf("電力計")>-1)z=2;
         if(index[s].indexOf("合計")>-1)z=3;
         if(z>0)sx=sx+1;
         if(z>0)year_p[sx]=year[s];
         if(z>0)month_p[sx]=month[s];
         if(z>0)credit_p[sx]=credit[s];
         if(z>0)com_p[sx]=com[s];
          if(z>0)vs[sx]=v[s];
          if(z>0)index_p[sx]=index[s];
         }
 
         for(s=1;s<datanumber+1;s++){
         if(com[s].length()<1)com[s]=com[s-1];
         }
         datanumber=sx;
 
 
        writefile("den/"+tr+".txt");
 
    }
 
 
    }
     void writefile(String file){ 
 
try{ 
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file))); 
 
for(s=1;s<datanumber+1;s++){ 
pw.print("<year>"); 
pw.print(year_p[s]); 
pw.print("</year>"); 
pw.print("<month>"); 
pw.print(month_p[s]); 
pw.print("</month>");
pw.print("<com>"); 
pw.print(com_p[s]); 
pw.print("</com>"); 
pw.print("<credit>"); 
pw.print(credit_p[s]); 
pw.print("</credit>");
pw.print("<index>"); 
pw.print(index_p[s]); 
pw.print("</index>");
pw.print("<value>"); 
pw.print(vs[s]); 
pw.println("</value>"); 
} 
 
System.out.println("ファイルに書きこみました。"); 
pw.close(); 
} catch(IOException ep){ System.out.println("入出力エラーです。"); } 
 
 
} 
 
 
 
 
 
 
}
 
最終更新:2015年03月31日 02:35