javac Compare.java
To run the program,
java Compare data.txt file.txt
import java.io.*;
public class Compare
{
public boolean contains(String str, String text)
{
boolean found=false;
if(0<=text.indexOf(str))
{
found=true;
}
return found;
}
private String readFile(String fileName)
{
String text="";
try
{
FileInputStream fis=new FileInputStream(fileName);
InputStreamReader isr=new InputStreamReader(fis,"utf-8");
BufferedReader reader=new BufferedReader(isr);
String line="";
while((line=reader.readLine())!=null)
{
//System.out.println(line);
text+=line+"\n";
}
}
catch(Exception e)
{
e.printStackTrace();
}
return text;
}
public void compareLine(String org, String dest)
{
String text=readFile(dest);
try
{
FileInputStream fis=new FileInputStream(org);
InputStreamReader isr=new InputStreamReader(fis,"utf-8");
BufferedReader reader=new BufferedReader(isr);
String line="";
while((line=reader.readLine())!=null)
{
if(contains(line,text))
{
System.out.print("o ");
}
else
{
System.out.print("x ");
}
System.out.println(line);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
if(1<args.length)
{
Compare compare=new Compare();
compare.compareLine(args[0],args[1]);
}
}
}