4
                String str = "";
            try {

                BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()));
                while (br.readLine() != null) {
                    str += br.readLine();
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            String replace = str.replace("HTTP Request: ", "")
                    .replace("Resource URL: ","")
                    .replace("Attribute\t\tDescription", "| Attribute | Type | Description |<P>|----|----|<P>")
                    .replace("Data Type | Max Length | Requirement |", "")
                    .replace("N/A", "Object")
                    .replace("String", "| String")
                    .replace("255 |", "")
                    .replace("Required", "**Required**")
                    .replace("Optional", "**Optional**")
                    .replace("Request Example <P>", "")
                    .replace("Response Example <P>", "Nothing");

            PrintWriter pw = null;

The BufferedReader ignores the first 3 lines and reads/converts the rest. Not sure as to what the issue is. I have tried other StackOverflow solutions but none of them seem to work!

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36

3 Answers3

7

The problem is here:

while (br.readLine() != null)

The time that you check if the br.readLine() is not null you have already read the line.To fix this you can try the following:

String line = br.readLine();
while (line != null){
    str +=line;
    line = br.readLine();
}
theVoid
  • 743
  • 4
  • 14
  • @Suhail Prasathong I am glad I helped,but remember to accept a solution to close the question,it does't have to be mine. – theVoid Jun 15 '16 at 05:08
2

You only check the return value of br.readLine() while you are supposed to treat it as well, here is the common code:

StringBuider buffer = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
    String line;
    while((line = br.readLine()) != null) {
        buffer.append(line);
    }
}
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
0

theVoid already told what problem is a gave a solution.

In the cases where cinditional statement are iterative functions, I always prefer to use

do{
    //task
    //Iterate and store result in var, like in your case
    var = br.readLine();
}while(var != null/*check on var rather than executing iteration*/);
Himanshu Shankar
  • 735
  • 1
  • 6
  • 24