4
Testing and Checking File Objects: file name and path File myFile = new File( "C:" + File.separator + "jdk1.5.0" + File.separator, ava" ); 11.2 .3. Providing a URI for a remote file File remoteFile = new File( new URI( "file:///index.htm" )); 11.2 .4. isAbsolute(): Returns true if the File object refers to an absolute pathname, and false otherwise. File myFile = new File( "C:" + File.separator + "jdk1.5.0" + Fi arator, "File.java" ); 11.2 .5. getParent(): Returns the name of the parent directory of the file or directory represented File myFile = new File( "C:" + File.separator + "jdk1.5.0" + parator, "File.java" ); 11.2 .6. getParentFile(): Returns the parent directory as a File object, or null if this File object does not have a File myFile = new File( "C:" + File.separator + "jdk1.5.0" + File tor, "File.java" ); System.out.println(myFile.getParentFile()); 11.2 .7. toString(): Returns a String representation of the current File object File myFile = new File( "C:" + File.separator + "jdk1.5.0" + File tor, "File.java" ); System.out.println(myFile.getParentFile()); 11.2 .8. exists(): Returns true if it exists and false otherwise File myFile = new File( "C:" + File.separator + "jdk1.5.0" + File tor, "File.java" ); System.out.println(myFile.exists()) 11.2 .9. isDirectory(): Returns true if it is an existing directory and false otherwise (myFile.isDirectory());

File

  • Upload
    phani

  • View
    213

  • Download
    0

Embed Size (px)

DESCRIPTION

files

Citation preview

Testing and Checking File Objects: file name and pathFile myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator,ava");11.2.3.Providing a !" for a remote fileFile remoteFile = new File(new U!(""ile:###i$de%.&tm"));11.2.#.is$bsol%te&': !et%rns tr%e if the File object refers to an absol%te pathname( and false other)ise.File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");11.2.*.getParent&': !et%rns the name of the parent director+ of the file or director+ representedFile myFile = new File("C:" + File.separator + "jdk1.5.0" + parator, "File.java");11.2.,.getParentFile&': !et%rns the parent director+ as a File object( or n%ll if this File object does not have a parent.File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");'ystem.o(t.pri$tl$(myFile.)et*are$tFile());11.2.-.to.tring&': !et%rns a .tring representation of the c%rrent File objectFile myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); 'ystem.o(t.pri$tl$(myFile.)et*are$tFile());11.2./.e0ists&': !et%rns tr%e if it e0ists and false other)iseFile myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");'ystem.o(t.pri$tl$(myFile.e%ists())11.2.1.is2irector+&': !et%rns tr%e if it is an e0isting director+ and false other)ise(myFile.is+ire,tory());11.2.13.isFile&': !et%rns tr%e if it is an e0isting file and false other)ise$(myFile.isFile());11.2.11.is4idden&': !et%rns tr%e if it is hidden and false other)ise(myFile.is-idde$());11.2.12.can!ead&': !et%rns tr%e if +o% are permitted to read the file and false other)ise.myFile.,a$ead());11.2.13.can5rite&': !et%rns tr%e if +o% are permitted to )rite to the file and false other)ise.$(myFile.,a$.rite()11.2.1#.get$bsol%tePath&': !et%rns the absol%te path for the director+ or file referenced b+ the c%rrent File objectmyFile.)et/0sol(te*at&())11.2.1*.get$bsol%teFile&': !et%rns a File object containing the absol%te path for the director+ or file referenced b+ the c%rrent File object.myFile.)et/0sol(teFile())11.2.1,.list&': !et%rns a string arra+ containing the children files and directoriesFile myFile = new File("C:" + File.separator);for('tri$) s: myFile.list())11.2.1-.listFiles&': !et%rns a File arra+ containing the children files and directoriesFile myFile = new File("C:" + File.separator);for(File s: myFile.listFiles())111.2.1/.length&': !et%rns the length of c%rrent file in long(myFile.le$)t&()11.2.11.Create a h%man6readable file si7eFile "ile = new File(",:22java.e%e"); long si3e = "ile.le$)t&();'tri$) display = FileUtils.0yteCo($t4o+isplay'i3e(si3e);11.2.23.last8odified&': !et%rns last modified time in milliseconds since midnight on 1st 9an%ar+ 11-3 :8T## Create a$ o0je,t t&at is a dire,toryFile my+ir = new File("C:#5ava6+ev");'ystem.o(t.pri$tl$(new +ate(my+ir.last7odi"ied()))11.2.21.renameTo&File path': !ename a file or director+File "ile = new File(",:22te%t.t%t");"ile.re$ame4o(new File(",:22te%t.t%t.0ak"));11.2.22.set!eadOnl+&': .ets the file as read6onl+ and ret%rns tr%e if the operation is s%ccessf%lFile "ile = new File(",:22te%t.t%t");"ile.setead8$ly();'ystem.o(t.pri$tl$("ile.,a$ead())11.2.23.Filtering a File ;ist11.2.2#.mkdir&': Creates a director+11.2.2*.mkdirs&': Creates a director+ incl%ding an+ parent directories11.2.2,.create