import java.io.*;
class pro{
String data,file;
int s,page,p1,p2;
int[] x=new int[5000];
int[] y=new int[5000];
String[] credit=new String[5000];
String[] opinion=new String[5000];
int xmlnumber;
public static void main(String [] args) {
pro test=new pro();
}
pro(){
for(page=5000;page<5500;page++){
file="data/";
file=file+page;
file=file+".txt";
System.out.println(file);
readfile(file);
xymaker(data);
for(s=1;s<xmlnumber;s++){
credit[s]=data.substring(x[s]+4,y[s]);
}
for(s=1;s<xmlnumber;s++){
p1=y[s];
p2=x[s+1];
opinion[s]="";
if(p2>p1)opinion[s]=data.substring(p1,p2);
}
s=xmlnumber;
p1=y[s];
p2=data.indexOf("</BODY>");
if(p2>p1)opinion[s]=data.substring(p1,p2);
for(s=1;s<xmlnumber+1;s++){
opinion[s]=opinion[s].replace("<BR>","");
opinion[s]=opinion[s].replace("</B>","");
}
file="gdata/";
file=file+page;
file=file+".txt";
writefile(file);
}
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter(file)));
for(s=1;s<xmlnumber+1;s++){
pw.print(credit[s]);
pw.print(",");
pw.println(opinion[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void xymaker(String data){
int s,p1;
s=0;
p1=data.indexOf("<B>○");
if(p1>0)s=s+1;
if(p1>0)x[s]=p1;
while(p1>1){
p1=data.indexOf("<B>○",p1+1);
if(p1>1)s=s+1;
if(p1>1)x[s]=p1;
}
xmlnumber=s;
for(s=1;s<xmlnumber+1;s++){
y[s]=data.indexOf("</B>",x[s]);
}
}
void readfile(String file){
String str;
BufferedReader br;
data="";
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"SJIS"));
while((str = br.readLine()) != null) {
data=data+str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
}
}
最終更新:2011年06月29日 10:42