1 Attachment(s)
Unicode string serach problem
Hi,
I am new in Java. Problem is the Unicode string. I have a Unicode file where I am searching a few words/sentence. The search string is defined as
String StringToBeSearch = "Because the Agent software is already";
When I am opening the file and try to compare it with the file content, it don’t succeeds. If I am opening that Unicode text file the contents are there.
What print the every line of the txt file and observed that the every latter have one more space like word “Because” is printed as “B e c a u s e”. Hence the search has failed.
public static boolean ReadFileAndSearchString()
{
String FileName = "Install.txt";
String StringToBeSearch = "Because the Agent software is already";
boolean found = false;
File file = new File(FileName);
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
String line = dis.readLine();
System.out.println(line);
int ret = line.indexOf(StringToBeSearch);
if ( ret >= 0 )
{
System.out.println("Got The text");
found = true;
break;
}
}
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return found;
}
also tried with the following code
FileInputStream fis = new FileInputStream(FileName);
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
but did not worked.
Providing my txt file as attachment.