呵呵,真抱歉刚才是用错文件了实际上,我现在的问题file writer 的东西问什么必须是在static理才可以用啊。不然他给我反一个"Exception in thread "main" java.lang.NoSuchMethodError: main"或者,我在static里怎样传递我的string值(line)去我的“writeString” method啊,我晕啊!!请高手指点------------------------------------------------------------import java.io.*; import java.util.StringTokenizer; import java.util.regex.Pattern; import java.util.regex.Matcher;public class ValBiseexport implement Datainput,Dataoutput{
static{ int i=0; int bytesRead=0; int counter=1; StringTokenizer st; File f =new File("C:\\Documents and Settings\\SEP10663\\Desktop\\BISEPORTA.txt");
if(!f.exists()) { System.out.println("no such file"); System.exit(0); }//the end of if else try{ FileReader fr=new FileReader(f); BufferedReader in=new BufferedReader(fr); while(i!=-1){ i=in.read(); String line=in.readLine();//read text row by row* Pattern pattern = Pattern.compile(","); Matcher matcher; ValBiseexport val=new ValBiseexport(); if(line.indexOf("''")!=-1){ //if check for single quote '' error File er=new File("C:/Documents and Settings/SEP10663/Desktop/ErrorReport/ErrorReport"+counter++ +".txt"); ValBiseexport val=new ValBiseexport(er,"rw"); val.writeChars(line);
//System.out.println("please check your single quote"); } if(line.indexOf("ORDERS_D") != -1){ matcher = pattern.matcher(line); int count = 0; while (matcher.find()) { count++; }//the end of while if(count!=2){ //System.out.println("od wrong"+count); }//the end of if count else{ //System.out.println("orders_d"); } }//the end of if orders
else if(line.indexOf("ORDERS_I") != -1){ matcher = pattern.matcher(line); int count1 = 0; while (matcher.find()) { count1++; }//the end of while if(count1!=23){ //System.out.println("oi wrong"+count1); }//the end of if count else{ //System.out.println("orders_i"); }
}//the end of if orders
else if(line.indexOf("ORDERS_U") != -1){ matcher = pattern.matcher(line); int count2 = 0; while (matcher.find()) { count2++; }//the end of while if(count2!=23){ //System.out.println("ou wrong"+count2); }//the end of if count2 else{ //System.out.println("orders_u"); } }//the end of if order
else if (line.indexOf("CUST_D")!=-1){ matcher = pattern.matcher(line); int count3 = 0; while (matcher.find()) { count3++; }//the end of while if(count3!=23){ //System.out.println("cd wrong"+count3); }//the end of if count3 else{ //System.out.println("cust_d"); } }//the end of if cust
else if (line.indexOf("CUST_I")!=-1){ matcher = pattern.matcher(line); int count4 = 0; while (matcher.find()) { count4++; }//the end of while if(count4!=1){ //System.out.println("ci wrong"+count4); }//the end of if count4 else{ //System.out.println("cust_i"); } }//the end of if cust
else if (line.indexOf("CUST_U")!=-1){ matcher = pattern.matcher(line); int count5 = 0; while (matcher.find()) { count5++; }//the end of while if(count5!=1){ //System.out.println("cu wrong"+count5); }//the end of if count5 else{ //System.out.println("cust_u"); } }//the end of if cust else if (line.indexOf("SEQUENCE_D")!=-1){ matcher = pattern.matcher(line); int count6 = 0; while (matcher.find()) { count6++; }//the end of while if(count6!=23){ //System.out.println("sd wrong"+count6); }//the end of if count6 else{ //System.out.println("sequence_d"); } }//the end of if sequence
else if (line.indexOf("SEQUENCE_I")!=-1){ matcher = pattern.matcher(line); int count7 = 0; while (matcher.find()) { count7++; }//the end of while if(count7!=7){ //System.out.println("si wrong"+count7); }//the end of if count7 else{ //System.out.println("sequence_i"); } }//the end of if sequence
else if (line.indexOf("SEQUENCE_U")!=-1){ matcher = pattern.matcher(line); int count8 = 0; while (matcher.find()) { count8++; }//the end of while if(count8!=23){ //System.out.println("wrong"+count8); }//the end of if count8 else{ //System.out.println("sequence_u"); } }//the end of if sequence if(i!=-1) bytesRead++; else in.close();
}//the end of try }catch (IOException ioe) { //System.out.println("IO error:"+ioe); }//the end of catch //System.out.println("bytes need from file:"+bytesRead); //System.out.println("bytes in File.length():"); }//the end of static
public void writeString(File f,String str){ BufferedWriter bw = new BufferedWriter(new FileWriter(f)); PrintWriter out = new PrintWriter(bw,ture); out.println("error line:" +line);
2、出错信息对不上号(SDK1.5)
(String.java:484)==>*/
(BufferedWriter.java:202)==>synchronized (lock) {
(ValBiseexport.java:42)==>bw.flush();
3、可能的情况是字符串长度不足2030,而试图获取第2030个字符,发生异常。
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.regex.Matcher;public class ValBiseexport implement Datainput,Dataoutput{
static{
int i=0;
int bytesRead=0;
int counter=1;
StringTokenizer st;
File f =new File("C:\\Documents and Settings\\SEP10663\\Desktop\\BISEPORTA.txt");
if(!f.exists())
{
System.out.println("no such file");
System.exit(0);
}//the end of if
else
try{
FileReader fr=new FileReader(f);
BufferedReader in=new BufferedReader(fr);
while(i!=-1){
i=in.read();
String line=in.readLine();//read text row by row*
Pattern pattern = Pattern.compile(",");
Matcher matcher;
ValBiseexport val=new ValBiseexport();
if(line.indexOf("''")!=-1){
//if check for single quote '' error
File er=new File("C:/Documents and Settings/SEP10663/Desktop/ErrorReport/ErrorReport"+counter++ +".txt");
ValBiseexport val=new ValBiseexport(er,"rw");
val.writeChars(line);
//System.out.println("please check your single quote");
}
if(line.indexOf("ORDERS_D") != -1){
matcher = pattern.matcher(line);
int count = 0;
while (matcher.find()) {
count++;
}//the end of while
if(count!=2){
//System.out.println("od wrong"+count);
}//the end of if count
else{
//System.out.println("orders_d");
}
}//the end of if orders
else if(line.indexOf("ORDERS_I") != -1){
matcher = pattern.matcher(line);
int count1 = 0;
while (matcher.find()) {
count1++;
}//the end of while
if(count1!=23){
//System.out.println("oi wrong"+count1);
}//the end of if count
else{
//System.out.println("orders_i");
}
}//the end of if orders
else if(line.indexOf("ORDERS_U") != -1){
matcher = pattern.matcher(line);
int count2 = 0;
while (matcher.find()) {
count2++;
}//the end of while
if(count2!=23){
//System.out.println("ou wrong"+count2);
}//the end of if count2
else{
//System.out.println("orders_u");
}
}//the end of if order
else if (line.indexOf("CUST_D")!=-1){
matcher = pattern.matcher(line);
int count3 = 0;
while (matcher.find()) {
count3++;
}//the end of while
if(count3!=23){
//System.out.println("cd wrong"+count3);
}//the end of if count3
else{
//System.out.println("cust_d");
}
}//the end of if cust
else if (line.indexOf("CUST_I")!=-1){
matcher = pattern.matcher(line);
int count4 = 0;
while (matcher.find()) {
count4++;
}//the end of while
if(count4!=1){
//System.out.println("ci wrong"+count4);
}//the end of if count4
else{
//System.out.println("cust_i");
}
}//the end of if cust
else if (line.indexOf("CUST_U")!=-1){
matcher = pattern.matcher(line);
int count5 = 0;
while (matcher.find()) {
count5++;
}//the end of while
if(count5!=1){
//System.out.println("cu wrong"+count5);
}//the end of if count5
else{
//System.out.println("cust_u");
}
}//the end of if cust else if (line.indexOf("SEQUENCE_D")!=-1){
matcher = pattern.matcher(line);
int count6 = 0;
while (matcher.find()) {
count6++;
}//the end of while
if(count6!=23){
//System.out.println("sd wrong"+count6);
}//the end of if count6
else{
//System.out.println("sequence_d");
}
}//the end of if sequence
else if (line.indexOf("SEQUENCE_I")!=-1){
matcher = pattern.matcher(line);
int count7 = 0;
while (matcher.find()) {
count7++;
}//the end of while
if(count7!=7){
//System.out.println("si wrong"+count7);
}//the end of if count7
else{
//System.out.println("sequence_i");
}
}//the end of if sequence
else if (line.indexOf("SEQUENCE_U")!=-1){
matcher = pattern.matcher(line);
int count8 = 0;
while (matcher.find()) {
count8++;
}//the end of while
if(count8!=23){
//System.out.println("wrong"+count8);
}//the end of if count8
else{
//System.out.println("sequence_u");
}
}//the end of if sequence
if(i!=-1)
bytesRead++;
else
in.close();
}//the end of try
}catch (IOException ioe)
{
//System.out.println("IO error:"+ioe);
}//the end of catch
//System.out.println("bytes need from file:"+bytesRead);
//System.out.println("bytes in File.length():");
}//the end of static
public void writeString(File f,String str){
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
PrintWriter out = new PrintWriter(bw,ture);
out.println("error line:" +line);
}//the end of writeString
}//the end of class