Buggy code:
public class WebMD_SocialMedia { public static void main ( String [ ] args ) throws IOException { HashMap < String , Integer > hashmap = new HashMap < String , Integer > ( ) ; HashMap < String , Integer > userMap = new HashMap < String , Integer > ( ) ; List < String > uniqueSet = new ArrayList < String > ( ) ; Pattern p8 = Pattern . compile ( ".{1,50}www.{1,500}" ) ; String [ ] fileNames = new String [ ] { "webmd_addiction" , "webmd_adhd" , "webmd_breast_cancer" , "webmd_diabetes" , "webmd_diet" , "webmd_fkids" , "webmd_heart" , "webmd_ms" , "webmd_pain" , "webmd_sexualhealth" } ; for ( String fileLog : fileNames ) { hashmap = new HashMap < String , Integer > ( ) ; userMap = new HashMap < String , Integer > ( ) ; uniqueSet = new ArrayList < String > ( ) ; BufferedReader br = new BufferedReader ( new FileReader ( ( ( "data//" + fileLog ) + ".csv" ) ) ) ; List < String > qidArray = new ArrayList < String > ( ) ; <START_BUG> BufferedWriter writer = new BufferedWriter ( new FileWriter ( ( ( "test//" + fileLog ) + "_staff_qid.txt" ) ) ) ; <END_BUG> while ( br . ready ( ) ) { String check = br . readLine ( ) ; String [ ] tokenizedTerms = check . split ( "\"" ) ; String nameToken = tokenizedTerms [ 3 ] ; if ( ( check . contains ( "www" ) ) | ( check . contains ( "http" ) ) ) { String check2 = "<seq2seq4repair_space>" ; String check3 = "<seq2seq4repair_space>" ; Matcher m8 = p8 . matcher ( check ) ; List < String > matchstring8 = new ArrayList < String > ( ) ; while ( m8 . find ( ) ) { check2 = ( check2 + "" ) + ( m8 . group ( ) ) ; matchstring8 . add ( m8 . group ( ) ) ; } Pattern p9 = Pattern . compile ( "https?\\:\\//\\//[\\-w\\.]*(\\:\\d+)?([\\w\\//\\_\\-\\.\\=\\?\\&\\%\\+\\@\\^\\~\\!\\#\\$]*)?[^www]|www\\.(\\:\\d+)?([\\w\\//\\_\\-\\.\\=\\?\\&\\%\\+\\@\\^\\~\\!\\#\\$]*)?[^www]" ) ; Matcher m9 = p9 . matcher ( check2 ) ; List < String > matchstring9 = new ArrayList < String > ( ) ; while ( m9 . find ( ) ) { check3 = ( check3 + "" ) + ( m9 . group ( ) ) ; matchstring9 . add ( m9 . group ( ) ) ; } Pattern p10 = Pattern . compile ( "www.*?(\\.com(?=\\W)|\\.com\\,?\\)?|\\.org(?=\\W)|\\.ORG(?=\\W)|\\.net(?=\\W)|\\.gov(?=\\W)|\\.co.uk|\\.html|\\.htm|\\.asp|\\.aspx|\\.edu|\\.us|treatment|\\-men(?=\\W)|\\.pdf|\\.ca\\//servlet|\\.ch(?=\\W)|\\.coream(?=\\W)|\\.ee(?=\\W))|www.*?(?=\\//)|(?<=http\\:\\//\\//).*?(?=\\//)|(?<=https\\:\\//\\//).*?(?=\\//)" ) ; Matcher m10 = p10 . matcher ( check3 ) ; List < String > matchstring10 = new ArrayList < String > ( ) ; while ( m10 . find ( ) ) { matchstring10 . add ( m10 . group ( ) ) ; for ( int i = 0 ; i < ( matchstring10 . size ( ) ) ; i ++ ) { if ( uniqueSet . contains ( matchstring10 . get ( i ) ) ) { int elementCount = Integer . parseInt ( hashmap . get ( matchstring10 . get ( i ) ) . toString ( ) ) ; elementCount ++ ; hashmap . put ( matchstring10 . get ( i ) , elementCount ) ; } else { uniqueSet . add ( matchstring10 . get ( i ) ) ; hashmap . put ( matchstring10 . get ( i ) , 1 ) ; } } } } } br . close ( ) ; SortedSet < Map . Entry < String , Integer > > sortedJournals = WebMD_SocialMedia . entriesSortedByValues ( hashmap ) ; for ( Map . Entry < String , Integer > ent : sortedJournals ) { if ( ( ( ( ( ( ( ( ( ( ent . getKey ( ) . contains ( "exchanges.webmd" ) ) || ( ent . getKey ( ) . contains ( "blogs.webmd" ) ) ) || ( ent . getKey ( ) . contains ( "facebook" ) ) ) || ( ent . getKey ( ) . contains ( "youtube" ) ) ) || ( ent . getKey ( ) . contains ( "intherooms" ) ) ) || ( ent . getKey ( ) . contains ( "friendsofbill" ) ) ) || ( ent . getKey ( ) . contains ( "rightactionforwomen" ) ) ) || ( ent . getKey ( ) . contains ( "hillbillyhousewife" ) ) ) || ( ent . getKey ( ) . contains ( "boards.webmd" ) ) ) || ( ent . getKey ( ) . contains ( "foxnews" ) ) ) { writer . write ( ( ( ( ( ent . getKey ( ) ) + "\t" ) + ( ent . getValue ( ) ) ) + '\n' ) ) ; System . out . println ( ( ( ( ent . getKey ( ) ) + "\t" ) + ( ent . getValue ( ) ) ) ) ; } } writer . close ( ) ; } } static class ValueComparator < K , V extends Comparable < V > > implements Comparator < K > { Map < K , V > map ; public ValueComparator ( Map < K , V > base ) { } @ Override public int compare ( K o1 , K o2 ) { } } static < K , V extends Comparable < ? super V > > SortedSet < Map . Entry < K , V > > entriesSortedByValues ( Map < K , V > map ) { } public static LinkedHashMap sortHashMapByValuesD ( HashMap passedMap ) { } }

Fix:
BufferedWriter writer = new BufferedWriter ( new FileWriter ( ( ( "test//" + fileLog ) + ".txt" ) ) ) ;