Looking at these lines shows the issue:
while(reader1.hasNext());{
String[] ary=reader1.next().split("");
file1.insert(ary);
}
while(reader2.hasNext());{
String[] ary=reader1.next().split("");
file2.insert(ary);
}
There should not be a semi-colon after while(reader2.hasNext())
or while(reader1.hasNext())
because this terminates the loop. I'm not actually sure why the semi colon here causes it to hang, but for some reason it does. I'm sure somebody will be able to help us both out here, but removing the semi-colons will fix the issue. It's strange, however, that the code is compilable.
Are you using an IDE? If you are, in the future you should attempt to debug your code within the IDE before asking for help on here. Saves everybody's time, and it's a good (read: necessary) skill to have.
Also for further reference, you have parameterised the type of Trie, but not specified a type when instantiating it.
Trie file1=new Trie("");
should be
Trie<String> file1=new Trie<String>("");