|
| |||||||||
| Tags: check, delete, directory, file, java, java io package |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to Check or Delete Directory in Java?
I have just started some basic things of I/O in Java programming language. I have not understood the methods for checking or deleting the files or directories. So thought that you guys will explain me much better. I am talking about the cases which are related to the I/O (input/output) of java.io package. So please tell me how to Check or Delete Directory in Java.?? Expecting some good help sooner.!! ![]()
__________________ Dimension 1100 (FMY032J) mini-tower 2.53ghz Intel Pentium 4 80 gig nfts HDD 512 RAM Main circuit board: Dell 0CF458 BIOS: Dell A00 Display: Intel(R) 82865G Graphics Controller [Display adaptor] Multimedia: Sound MAX Integrated Digital Audio Windows XP Home SP2 |
|
#2
| ||||
| ||||
| Re: How to Check or Delete Directory in Java?
You can use the checkAccess(AccessMode) method, if you want to verify that a file exists and that the program can access it as needed. The varargs argument can be any combination of the following AccessMode options :
__________________ IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people.... |
|
#3
| ||||
| ||||
| Re: How to Check or Delete Directory in Java?
I have provided you with the sample of coding that explains to verify the particular file exists and that the program has the ability to execute the file. The code I have used is for the Path which is a file and not a directory. Just look at the coding : Code: import static java.nio.file.AccessMode.*;
Path file = ...;
try {
file.checkAccess(READ, EXECUTE);
} catch (IOException x) {
return;
}
__________________ 3.2 (northwood) 2gig ramATI AIW X800xt 256mb Gigabyte GA-8knxp 875p Chipset Optiwrite 8X DVD Burner Win XP PRO Sp2 (Works Perfectly) 2 SATA Raptor 74gig Raid 0 2 7200 IDE 320gig HD |
|
#4
| ||||
| ||||
| Re: How to Check or Delete Directory in Java?
You can also check whether two paths locate the same file. You will have to use the isSameFile(Path) method that can compare two paths to determine if they locate the same file on the file system. For doing that you can use the following sample of the code : Code: Path pa1 = ...;
Path pa2 = ...;
try {
if (pa1.isSameFile(pa2)) {
}
} catch (IOException x) {
return;
} |
|
#5
| ||||
| ||||
| Re: How to Check or Delete Directory in Java?
You can delete files, directories or links. You must keep in mind while deleting the symbolic links, the link is deleted and not the target of the link. Two deletion methods are provided by the Path class :
|
|
#6
| ||||
| ||||
| Re: How to Check or Delete Directory in Java?
I think that catching an exception is always useful. If you want to catch the exception to determine why the delete failed, you will have to write the code as below : Code: try {
path.delete();
} catch (NoFileException x) {
System.err.format("%s: no mentioned file or directory%n", path);
} catch (DirectoryNotEmptyException x) {
System.err.format("%s not empty%n", path);
} catch (IOException x) {
System.err.println(x);
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to Check or Delete Directory in Java?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Batch file to check directory | Trini Alvarado | Software Development | 5 | 01-04-2010 12:00 PM |
| How to check if file exists in directory with Php | Zool | Software Development | 3 | 03-11-2009 12:36 PM |
| Active Directory Forest Health Check | answrman | Active Directory | 5 | 20-02-2009 07:07 PM |
| Powershell: To check a directory exists or not? | Chandrakant81 | Software Development | 3 | 18-02-2009 06:26 PM |
| A health-check script for Active Directory on Win 2000/2003 | JackFlash | Active Directory | 5 | 19-02-2007 02:44 PM |