6 Replies - 475 Views - Last Post: 26 December 2012 - 10:18 AM Rate Topic: -----

#1 theinarasu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 12

how to search file

Posted 25 December 2012 - 12:36 PM

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 ..
Is This A Good Question/Topic? 0
  • +

Replies To: how to search file

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2734
  • View blog
  • Posts: 11,515
  • Joined: 20-September 08

Re: how to search file

Posted 25 December 2012 - 01:30 PM

http://technojeeves....xt-file-in-java
Was This Post Helpful? 1
  • +
  • -

#3 theinarasu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 12

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?
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

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.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2734
  • View blog
  • Posts: 11,515
  • Joined: 20-September 08

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
Was This Post Helpful? 0
  • +
  • -

#6 theinarasu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-October 12

Re: how to search file

Posted 26 December 2012 - 09:59 AM

View Postg00se, 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 ?
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2734
  • View blog
  • Posts: 11,515
  • Joined: 20-September 08

Re: how to search file

Posted 26 December 2012 - 10:18 AM

Pass the search string and the starting directory to the search method
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1