hello hai...
i want to search corrent match text file in folder ...how ?
if i type 12345 it must show the contain in the text file ..
pls i need help ..
how to search file
Page 1 of 16 Replies - 248 Views - Last Post: 26 December 2012 - 10:18 AM
Replies To: how to search file
#3
Re: how to search file
Posted 26 December 2012 - 04:43 AM
String n = JOptionPane.showInputDialog(null, "Enter Accountnumber");
String searchfile = ".txt";
try {
ArrayList DisCusDetail = new ArrayList();
File f = new File("");
File list[] = f.listFiles();
for (File fi : list) {
if (fi.isDirectory()) {
DisCusDetail.add(fi);
} else {
String fname = fi.toString();
if (fname.startsWith("sada") && fname.endsWith(searchfile)) {
System.out.println(fname);
System.out.println("yes");
}
}
}
if (!DisCusDetail.isEmpty()) {
int i = 0;
while (!DisCusDetail.isEmpty()) {
File file = (File) DisCusDetail.get(i);
File lis[] = file.listFiles();
String dname = DisCusDetail.get(i).toString();
DisCusDetail.remove(i);
for (File li : lis) {
if (li.isDirectory()) {
DisCusDetail.add(li);
} else {
String finame = dname + File.separator + li.getName();
if (finame.startsWith("sada") &&finame.endsWith(searchfile)) {
System.out.println(finame);
System.out.println("yes1");
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
i want to search file when user enter the file name ....so i try to do like this ....but got error ...nullpointererror...what is the problem?
#4
Re: how to search file
Posted 26 December 2012 - 08:46 AM
Null pointer error: Something in your code - maybe in what you posted, maybe not - is pointing to a null, commonly an instance of an object that hasn't been initialized or some field/method/etc. of an uninitialized object.
Before we can help you further, you'll need to post the exact error message, copied and pasted from just as it appears at your end, and enough of the code to which the error message points to figure out what's going on. If you continue posting snippets (and that's fine) you'll have to provide a translation from the line number cited by the error message to the corresponding line in the code you've posted.
Before we can help you further, you'll need to post the exact error message, copied and pasted from just as it appears at your end, and enough of the code to which the error message points to figure out what's going on. If you continue posting snippets (and that's fine) you'll have to provide a translation from the line number cited by the error message to the corresponding line in the code you've posted.
#5
Re: how to search file
Posted 26 December 2012 - 09:12 AM
You don't ever want to add to and subtract from a List simultaneously. Nor do you want to repeat interation code. You just need a simple recursive routine with a FileFilter to restrict to the files you're interested in
#6
Re: how to search file
Posted 26 December 2012 - 09:59 AM
g00se, on 26 December 2012 - 09:12 AM, said:
You don't ever want to add to and subtract from a List simultaneously. Nor do you want to repeat interation code. You just need a simple recursive routine with a FileFilter to restrict to the files you're interested in
hello sir goose...ya i got it ...but how to i match the user input with it ...can you explain it ?
#7
Re: how to search file
Posted 26 December 2012 - 10:18 AM
Pass the search string and the starting directory to the search method
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|