-4

I have some few files of different extensions like .rdf, .pkg,.fmb,.sql and .ldt. In these files I have to find that some specific keywords are present or not. So for this purpose I used two ways.

1st approach

String content = FileUtils.readFileToString(file); 

2nd approach

byte[] b = FileUtils.readFileToByteArray(fl);
                String read = new String(b);

now after getting these strings I search the keywords. The problem is I'm not sure whether from these approaches I'll be able to scan the entire file or not. Since those files are not text files so When I print these Strings in console , half the text is no readable. So I'm not sure whether this approach gives me the correct result or not. Please tell me how these two methods work. And will it give me all the keywords present in those files or not. Please guide.

Harshita Sethi
  • 2,035
  • 3
  • 24
  • 46

1 Answers1

0

If there is only one line in file, you can use the 1st approach:

String content = FileUtils.readFileToString(file); 

if there are more lines, you can use this approach:

String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\testing.txt"));
while ((sCurrentLine = br.readLine()) != null) {
    System.out.println(sCurrentLine);
}
Mauro Midolo
  • 1,841
  • 3
  • 14
  • 34