Results 1 to 12 of 12
  1. #1
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Post Exception throws when I read File

    Hello Friends
    I Devloping the File Searching Project I hava an Problem with the system files.When i read the system volume information file it throws the null pointer exception so i cant contniue my search.the same exception will appear when read the protected files........

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Without seeing the code and the full text of the error message, not able to help much.

  3. #3
    Join Date
    Jul 2008
    Posts
    33
    Rep Power
    0

    Default

    Without any code we cannot guess but you could try to add a condition before reading like != null
    :DMy community with sourcode and examples :D
    Java remote image server/client working proof of concept: uitstekendeaccu.nl/tmp/

  4. #4
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Default Here is the code

    import java.io.*;
    import java.util.Vector;

    class Filelist
    {
    public static void main(String[] args)
    {
    int dir=0,j=0;
    File f;
    try
    {
    Vector drivevect=new Vector();
    File []drives = new File("").listRoots();
    for(j=0;j<drives.length;j++)
    {
    drivevect.add(drives[j].toString());
    //System.out.println("sss"+drivevect);
    }
    for(dir=0;dir<drivevect.size();dir++)
    {
    f=new File((String)drivevect.elementAt(dir));
    File []f1=f.listFiles();
    for(File ftemp:f1)
    {
    //System.out.println(ftemp.getParentFile()+ftemp.get Name());
    if(ftemp.isDirectory()==true)
    {
    System.out.println(ftemp);
    File fe=new File(ftemp.getCanonicalPath());
    File []f1e=fe.listFiles();
    for(File ftempe:f1e)
    {
    if(ftempe.isDirectory()==true)
    {
    System.out.println(ftempe);
    }
    }
    }
    }
    }
    }
    catch (Exception e)
    {
    System.out.println(e);
    }

    }
    }
    OUTPUT

    C:\Config.Msi
    C:\Documents and Settings
    C:\Documents and Settings\Admin
    C:\Documents and Settings\Administrator
    C:\Documents and Settings\All Users
    C:\Documents and Settings\Default User
    C:\Documents and Settings\LocalService
    C:\Documents and Settings\NetworkService
    C:\Program Files
    C:\Program Files\Adobe
    C:\Program Files\Ahead
    C:\Program Files\Common Files
    C:\Program Files\ComPlus Applications
    C:\Program Files\Crocodile Clips
    C:\Program Files\CyberLink
    C:\Program Files\DameWare Development
    C:\Program Files\DameWare Development(2)
    C:\Program Files\DigiPortal Software
    C:\Program Files\EditPlus 3
    C:\Program Files\Epigon
    C:\Program Files\FlashGuard
    C:\Program Files\InstallShield Installation Information
    C:\Program Files\Intel
    C:\Program Files\Internet Explorer
    C:\Program Files\Java
    C:\Program Files\JFormDesigner
    C:\Program Files\KuralSoft
    C:\Program Files\Messenger
    C:\Program Files\Microsoft ActiveSync
    C:\Program Files\microsoft frontpage
    C:\Program Files\Microsoft Office
    C:\Program Files\Movie Maker
    C:\Program Files\MSN
    C:\Program Files\MSN Gaming Zone
    C:\Program Files\NaturalSoft
    C:\Program Files\NetMeeting
    C:\Program Files\Online Services
    C:\Program Files\Outlook Express
    C:\Program Files\Real
    C:\Program Files\Realtek
    C:\Program Files\Symantec
    C:\Program Files\Symantec AntiVirus
    C:\Program Files\Uninstall Information
    C:\Program Files\VideoLAN
    C:\Program Files\Windows Media Player
    C:\Program Files\Windows NT
    C:\Program Files\WindowsUpdate
    C:\Program Files\WinRAR
    C:\Program Files\xerox
    C:\Program Files\Yenka
    C:\RECYCLER
    C:\RECYCLER\S-1-5-21-1645522239-884357618-682003330-1003
    C:\RECYCLER\S-1-5-21-1645522239-884357618-682003330-500
    C:\System Volume Information
    java.lang.NullPointerException

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Replace
    System.out.println(e);
    with
    e.printStackTrace();

    That will show you what line in your program the error occurred.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You get an exception here when you trying to access the System Volume Information folder. It's a folder and you have check it, if it's true searching inside of it for sud directories. But the issue is, you don't have permission for that folder. I think even you log in as an admin, you can't access it. So the solution here is, before searching any folder check the permission. Basically this is happened when you try to access/ read a folder content.

  7. #7
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Default

    Thanks for ur replay

  8. #8
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Default

    Thank for ur replay that is very helpful for me

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Did you solve the question? Is there and access permission issue. It's better if you can let me here what happened. Because may be others can helpful your result who comes with a similar issue. :)

  10. #10
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Default

    Yes i Solve it by checking the condition File not equal to null

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You mean that you are checking the availability of the file? I don't there is such an issue, can you clear up little more here.

  12. #12
    Juggler's Avatar
    Juggler is offline Member
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    16
    Rep Power
    0

    Default

    try
    {
    Vector drivevect=new Vector();
    File []drives = new File("").listRoots();
    for(j=0;j<drives.length;j++)
    {
    drivevect.add(drives[j].toString());
    //System.out.println("sss"+drivevect);
    }
    for(dir=0;dir<drivevect.size();dir++)
    {
    f=new File((String)drivevect.elementAt(dir));
    File []f1=f.listFiles();
    if (f1!=null)//this condition to check for availability
    {

    for(File ftemp:f1)
    {
    //System.out.println(ftemp.getParentFile()+ftemp.get Name());
    if(ftemp.isDirectory())
    {
    System.out.println(ftemp);

    //System.out.println(path+"\n"+filename);
    File fe=new File(ftemp.getCanonicalPath());
    File []f1e=fe.listFiles();
    if (f1e !=null)//this condition to check for availability
    {

    for(File ftempe:f1e)
    {
    if(ftempe.isDirectory())
    {
    System.out.println(ftempe);

    }
    }
    }//if2
    }
    }
    }//if1
    }
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }


    when the first loop will execute system vloume information file will be read
    when the second loop execute the file will not read because that was protected file so i cant read so it return the null value .so i check the condition for null value before the loop start

Similar Threads

  1. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  2. Read file
    By tajinvillage in forum Threads and Synchronization
    Replies: 0
    Last Post: 01-29-2008, 09:10 AM
  3. Main method with throws Exception
    By bugger in forum New To Java
    Replies: 3
    Last Post: 01-07-2008, 02:48 PM
  4. throws Exception
    By javaplus in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 07:32 PM
  5. read txt file
    By sureshsri1981 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-05-2007, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •