java - Why does my program not read full files? -


i have written code in java read content of file. working small line of file not more 1000 line of file. please tell me me error have made in below program.

program:

import java.io.datainputstream; import java.io.dataoutputstream; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.util.regex.matcher; import java.util.regex.pattern;  public class aaru {   public static void main(string args[]) throws filenotfoundexception   {     file sourcefile = new file("e:\\parser\\parse3.txt");     file destinationfile = new file("e:\\parser\\new.txt");     fileinputstream filein = new fileinputstream(sourcefile);     fileoutputstream fileout = new fileoutputstream(destinationfile);     datainputstream datain = new datainputstream(filein);     dataoutputstream dataout = new dataoutputstream(fileout);      string str = "";     string[] st;     string sub[] = null;     string word = "";     string contents = "";     string total = "";      string stri = "";     try     {       while ((contents = datain.readline()) != null)       {         total = contents.replaceall(",", "");         string str1 = total.replaceall("--", "");         string str2 = str1.replaceall(";", "");         string str3 = str2.replaceall("&", "");         string str4 = str3.replaceall("^", "");         string str5 = str4.replaceall("#", "");         string str6 = str5.replaceall("!", "");         string str7 = str6.replaceall("/", "");         string str8 = str7.replaceall(":", "");         string str9 = str8.replaceall("]", "");         string str10 = str9.replaceall("\\?", "");         string str11 = str10.replaceall("\\*", "");         string str12 = str11.replaceall("\\'", "");           pattern pattern =             pattern.compile("\\s+", pattern.case_insensitive | pattern.dotall | pattern.multiline);         matcher matcher = pattern.matcher(str12);         //boolean check = matcher.find();         string result = str12;         pattern p = pattern.compile("^www\\.|\\@");         matcher m = p.matcher(result);         stri = m.replaceall(" ");          int i;         int j;          st = stri.split("\\.");          (i = 0; < st.length; i++)         {           st[i] = st[i].trim();           /*if(st[i].startswith(" "))           st[i]=st[i].substring(1,st[i].length);*/           sub = st[i].split(" ");            if (sub.length > 1)           {             (j = 0; j < sub.length - 1; j++)             {               word = word + sub[j] + "," + sub[j + 1] + "\r\n";              }           }           else           {             word = word + st[i] + "\r\n";           }         }       }        system.out.println(word);       dataout.writebytes(word + "\r\n");        filein.close();       fileout.close();       datain.close();       dataout.close();     } catch (exception e)     {       system.out.print(e);     }   } } 

it's not obvious why code doesn't read full files, here 2 hints:

first: don't use datainputstream reading full lines. instead wrap fileinputstream in inputstreamreader (ideally providing encoding) , bufferedreader (as documented javadoc of datainputstream.readline()):

like this:

bufferedreader reader = new bufferedreader(new inputstreamreader(filein, "utf-8")); 

second: when don't know how handle exception at least print stack trace this:

catch(exception e) {   e.printstacktrace(); } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -