0

I have the following code however when I am reading from an input, the input is not being read correctly. The input is two lines of code however the first line isn't being read correctly if it is too large (1 million characters)

package usaco;
import java.io.*;
import java.util.*;

public class Censoring {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(("C:/Users/Eric Gan/workspace/12in.txt")));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("C:/Users/Eric Gan/workspace/myout.txt")));
        String input = br.readLine();
        String censor = br.readLine();

        br.close();

        pw.println(input);
        pw.close();

        System.out.println(input);
        System.out.println(censor);

        while(input.contains(censor))
            {
                input = input.replace(censor, "");
            }

    }
}
cdosborn
  • 3,111
  • 29
  • 30
Eric Gan
  • 23
  • 4
  • possible dupli : http://stackoverflow.com/questions/7413830/java-read-line-from-file – Tharif Mar 22 '15 at 06:51
  • What do you mean by "not being read correctly"? Not reading complete line? Have you tried with small string? In that case is it showing correct result? – Kartic Mar 22 '15 at 06:56
  • The code looks ok to me. Could printing the lines to stdout to determine if the issue is with the reading or the writing. –  Mar 22 '15 at 10:10
  • Do you mean that you don't see all the input when printing with `System.out.println()`? That's normal. – blueygh2 Mar 22 '15 at 12:32
  • If i use a small string it displays the correct amount however with a large string it cuts some parts out. When I write it to a file I'm not seeing the whole thing. – Eric Gan Mar 22 '15 at 18:09
  • I stress tested your code with a file that has 128388040 chars on a single line. Nothing is wrong from what I can tell. You need to update your code above to be the smallest such that the error is reproducible. You need to define what is wrong. Provide sample input and sample output. – cdosborn Mar 26 '15 at 03:36

0 Answers0