To search for a string in a file and to be written with a string that matches the second string, It takes 15-20 minutes. ZIP file 70MB (compressed state)
My source code:
Getting zip file entries
zipFile = new zip file (Source_file_name); Entries = zipfile.entrees (); While (entries. Masks) {ZIP Entry Entry = (ZIP Entry) Entries. NXElment (); If (entry.isDirectory ()) {continue; } SearchString (Thread.currentThread (), entry.getName (), new BufferedInputStream (zipFile.getInputStream (entry)), Out_File, search_string, statistics); } ZipFile.close (); String Search Public Zero Search String (Thread Seethhide, String Source_file, Buffered InStस्टInIn, File Outfile, String Search, String Statistics) IOException throws {int count = 0; Int countw = 0; Int countl = 0; String s; String [] str; Buffardrider br2 = new bufferedReader (new InputStreamReader (in)); Println (CThread.currentThread ()); While ((s = br2.readLine ()) = null) {str = s.split (search); Count = str.length - 1; Countw + = Calculation; // word count if (s.contains (search)) {countl ++; // Line Count WriteFile (CThread, S, outfile.toString (), Search); }} Br2.close (); In.close (); } ------------------------------------------------- ------------------------------- Public Zero WriteFile throws IOException (Thread SeatHide, String Line, String Out, String Search) { Buffedwar buffer buffer = null; System.out.println ("article thread" + CThread.currentThread ()); BufferedWriter = New buffed vetter (new flumerwriter (outside, true)); BufferedWriter.write (line); BufferedWriter.newLine (); BufferedWriter.flush (); }
Please help me. It actually takes 10 minutes for 10 minutes using threads to get compressed for 40 minutes and 15 MB after a file of 70 MB is. Any way to reduce time.
You are reopening the file output handle for every single line, you write.
There is a large scale display effect on this, beyond other performance problems Instead, I recommend making a buffet wallter
once (like on the first match) and then keep it open, writing each match line and then Writer Closing
when complete
In addition, remove the call at flush ()
;
Comments
Post a Comment