package change;
import java.io.*;
import java.io.File;
public class pro {
int s,datanumber,sx;
String[] data=new String[5000];
String[] credit=new String[5000];
String file,str;
int creditnumber;
String[][] csvdata=new String[5000][20];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
File x=new File("data");
String[] fx=x.list();
file="data/"+fx[0];
readfile(file);
str=data[1];
credit(str);
for(s=1;s<datanumber+1;s++){
for(sx=1;sx<creditnumber+1;sx++){
csvdata[s][sx]=catchword(data[s],credit[sx]);
}
}
writefile("ren.txt");
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<datanumber;s++){
for(sx=1;sx<creditnumber;sx++){
pw.print(csvdata[s][sx]);
pw.print(",");
}
sx=creditnumber;
pw.println(csvdata[s][sx]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String catchword(String str,String word){
String str1,str2,strx;
int p1,p2;
str1="<"+word+">";
str2="</"+word+">";
p1=str.indexOf(str1);
p2=str.indexOf(str2);
strx=str.substring(p1,p2);
strx=strx.replace(str1,"");
return strx;
}
void credit(String str){
int p1,sx;
int[] x=new int[100];
int[] y=new int[100];
String[] subcredit=new String[600];
int number;
sx=0;
p1=str.indexOf("<");
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
}
number=sx;
for(sx=1;sx<number+1;sx++){
y[sx]=str.indexOf(">",x[sx]);
}
for(sx=1;sx<number+1;sx++){
subcredit[sx]=str.substring(x[sx]+1,y[sx]);
}
creditnumber=number/2;
for(sx=1;sx<creditnumber+1;sx++){
credit[sx]=subcredit[2*sx-1];
}
}
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;
}
}
最終更新:2013年12月14日 01:17