Results 1 to 12 of 12
- 08-10-2008, 07:21 AM #1
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........
- 08-10-2008, 01:58 PM #2
Without seeing the code and the full text of the error message, not able to help much.
- 08-10-2008, 10:49 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 33
- Rep Power
- 0
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/
- 08-12-2008, 04:31 PM #4
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
- 08-12-2008, 04:55 PM #5
Replace
System.out.println(e);
with
e.printStackTrace();
That will show you what line in your program the error occurred.
- 08-13-2008, 05:50 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 08-13-2008, 02:55 PM #7
Thanks for ur replay
- 08-13-2008, 02:57 PM #8
Thank for ur replay that is very helpful for me
- 08-14-2008, 06:21 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 08-14-2008, 05:47 PM #10
Yes i Solve it by checking the condition File not equal to null
- 08-15-2008, 07:38 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 08-18-2008, 06:09 PM #12
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
-
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM -
Read file
By tajinvillage in forum Threads and SynchronizationReplies: 0Last Post: 01-29-2008, 09:10 AM -
Main method with throws Exception
By bugger in forum New To JavaReplies: 3Last Post: 01-07-2008, 02:48 PM -
throws Exception
By javaplus in forum New To JavaReplies: 1Last Post: 11-06-2007, 07:32 PM -
read txt file
By sureshsri1981 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-05-2007, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks