See More

---------------------------- Files | ---------------------------- # ²Ù×÷ÎļþµÄ¾²Ì¬¹¤¾ßÀà,ºÜÅ£±Æ ---------------------------- Files-¾²Ì¬·½·¨ | ---------------------------- //=======================ÎļþÐÅÏ¢ String probeContentType(Path path) * »ñÈ¡ÎļþÀàÐÍ boolean isHidden(Path path); * ÅжÏÖ¸¶¨µÄpathÊÇ·ñÊÇÒþ²ØÎļþ/Ŀ¼ boolean exists(Path path, LinkOption... options); * ÅжÏÖ¸¶¨µÄÎļþÊÇ·ñ´æÔÚ boolean notExists(Path path, LinkOption... options) * ÅжÏÖ¸¶¨µÄÎļþÊÇ·ñ´æÔÚ boolean isDirectory(Path path, LinkOption... options); * ÊÇ·ñÊÇĿ¼ boolean isReadable(Path path); * ÊÇ·ñ¿É¶Á boolean isWritable(Path path); * ÊÇ·ñ¿Éд boolean isRegularFile(Path path); * ÅжÏÎļþÊÇ·ñÊÇÕý³£Îļþ boolean isExecutable(Path path); * ÅжÏÎļþÊÇ·ñ¿ÉÖ´ÐÐ boolean isSameFile(Path path, Path path2); * ÅжÏÎļþÊÇ·ñÊÇͬһ¸öÎļþ long size(Path path); * ·µ»ØÖ¸¶¨ÎļþµÄ´óС FileStore getFileStore(Path path); * »ñȡָ¶¨ path ËùÔÚµÄÅÌ·û //=======================ÎļþÐÅÏ¢(ÊôÐÔÏà¹Ø) V getFileAttributeView(Path path,Class type,LinkOption... options) * »ñÈ¡pathµÄÎļþµÄÖ¸¶¨ÀàÐ͵ÄÊôÐÔÃèÊö¶ÔÏó * ¸ù¾Ý type ½Ó¿ÚÀ´·µ»Ø²»Í¬ÀàÐ͵ÄÊôÐÔÃèÊö¶ÔÏó * »ù±¾ÊôÐÔ BasicFileAttributeView * ÎļþËùÓÐÕß FileOwnerAttributeView * ×Ô¶¨ÒåÊôÐÔ UserDefinedFileAttributeView ... Path setAttribute(Path path, String attribute, Object value,LinkOption... options) * ¸øÖ¸¶¨ÎļþµÄÖ¸¶¨ÊôÐÔÉèÖÃÖµ Object getAttribute(Path path, String attribute,LinkOption... options) * »ñȡָ¶¨ÎļþµÄÖ¸¶¨Ãû³ÆµÄÊôÐÔ FileTime getLastModifiedTime(Path path, LinkOption... options) * »ñÈ¡Îļþ×îºóµÄÐÞ¸Äʱ¼ä Path setLastModifiedTime(Path path, FileTime time); * ÉèÖÃ×îºóÐÞ¸Äʱ¼ä UserPrincipal getOwner(Path path, LinkOption... options); * ·µ»ØÎļþËùÓÐÕß * ·µ»Ø½Ó¿Ú:UserPrincipal µÄʵÀý Path setOwner(Path path, UserPrincipal owner); * ÉèÖÃÎļþËùÓÐÕß Path setPosixFilePermissions(Path path,Set perms) * ÉèÖÃÎļþµÄPOSIXȨÏÞ¡£ Set getPosixFilePermissions(Path path, LinkOption... options); * »ñÈ¡ÎļþµÄȨÏÞÐÅÏ¢ //=======================Á¬½Ó boolean isSymbolicLink(Path path); * ÅжÏÊÇ·ñÊÇÈíÁ¬½Ó¶î Path readSymbolicLink(Path path); * ͨ¹ýÈíÁ¬½Ó»ñÈ¡ÕæÊµµÄÎļþ¶ÔÏó Path createSymbolicLink(Path link,Path target, FileAttribute>... attrs) * ´´½¨ÈíÁ¬½Ó Path createLink(Path link,Path existing); * ´´½¨Ó²Á¬½Ó * link ¿ì½Ý·½Ê½µØÖ·,existing ÒѾ­´æÔÚµÄÎļþ //=======================¶ÁÈ¡ byte[] readAllBytes(Path path); * °ÑÖ¸¶¨Path±íʾµÄÎļþ¶ÁÈ¡µ½×Ö½ÚÊý×é List readAllLines(Path path,Charset charset); * °ÑÖ¸¶¨µÄÎı¾Îļþ,ÒÔÖ¸¶¨µÄ×Ö·û¼¯Ò»ÐÐÒ»ÐеĶÁÈ¡µ½ListÖÐ //=======================дÈë Path write(Path path,byte[] bute,OpenOption penOption...); * °Ñ×Ö½ÚдÈëµ½ path * penOptionÊÇÒ»¸ö±ê¼Ç½Ó¿Ú,ÓÃÓÚÖ¸¶¨Ð´ÈëµÄģʽ Path write(Path path, Iterable extends CharSequence> lines,OpenOption penOption...); * ͬÉÏ,дÈëµÄÊÇ lines ×ÓÀàÖеÄÊý¾Ý * ÀýÈç:List ÖеÄÊý¾Ý //=======================ɾ³ý void delete(Path path); * ɾ³ý,Èç¹û·Ç¿ÕÎļþ¼Ð.ÔòɾÅ׳öÒì³£ boolean deleteIfExists(Path path) * ɾ³ýÎļþ,Èç¹û²»´æÔÚ.²»»áÅ׳öÒì³£ //=======================»ñÈ¡Á÷ InputStream newInputStream(Path path,OpenOption penOption...); * »ñȡָ¶¨PathµÄInputStream OutputStream newOutputStream(Path path,OpenOption penOption...); * »ñȡָ¶¨µÄOutputStream BufferedReader newBufferedReader(Path path,OpenOption penOption...); * »ñȡָ¶¨µÄ BufferedReader * ÓиöÖØÔØ·½·¨,¿ÉÒÔÖ¸¶¨ Charset BufferedWriter newBufferedWriter(Path path,OpenOption penOption...); * »ñÈ¡BufferedWriter * ÓиöÖØÔØ,¿ÉÒÔÖ¸¶¨ Charset Stream lines(Path path); * ·µ»ØÁ÷ * ÓиöÖØÔØ,¿ÉÒÔÉèÖà Charset SeekableByteChannel newByteChannel(Path path, OpenOption... options); * »ñÈ¡ SeekableByteChannel ¹ÜµÀ * SeekableByteChannel ÊÇ FileChannel µÄ¸¸Àà SeekableByteChannel newByteChannel(Path path,Set extends OpenOption> options,FileAttribute>... attrs); * ͬÉÏ,¿ÉÒÔÉèÖÃÊôÐÔ DirectoryStream newDirectoryStream(Path dir); * »ñȡĿ¼Á÷,ÓÐÁ©ÖØÔØ.¿ÉÒÔÒÔ×Ö·û´®ÐÎʽºÍº¯Êý½Ó¿ÚµÄ·½Ê½ÉèÖùýÂËÆ÷ Stream find(Path start, int maxDepth, BiPredicate matcher, FileVisitOption... options) * ÔÚ start Ŀ¼ÖмìË÷Îļþ,²ã´ÎÉî¶ÈΪ:maxDepth * ͨ¹ýµ÷Óà matcher º¯Êý½Ó¿ÚÀ´¹ýÂËÎļþ/Îļþ¼Ð //=======================±éÀú DirectoryStream newDirectoryStream(Path dir); * »ñÈ¡ dir ϵÄËùÓÐÒ»¼¶Ä¿Â¼ºÍÎļþ DirectoryStream newDirectoryStream(Path dir,String parrten); * »ñÈ¡ dir ϵÄËùÓÐÒ»¼¶Ä¿Â¼ºÍÎļþ,¿ÉÒÔͨ¹ý parrten ±í´ïʽÀ´¹ýÂËÎļþ»òÕßĿ¼ DirectoryStream newDirectoryStream(Path dir,DirectoryStream.Filter super Path> filter) * »ñÈ¡ dir ϵÄËùÓÐÒ»¼¶Ä¿Â¼ºÍÎļþ,¿ÉÒÔͨ¹ý filter ±í´ïʽÀ´¹ýÂËÎļþ»òÕßĿ¼ Stream walk(Path start, FileVisitOption... options) * µÝ¹éĿ¼,·µ»Ø Stream Stream walk(Path start, int maxDepth, FileVisitOption... options) * ͬÉÏ,¶àÒ»¸ö maxDepth À´ÏÞÖÆ±éÀúµÄ²ã´Î * options À´¾ö¶¨ÊÇ·ñÒª¸ú×ÙÁ¬½Ó Path walkFileTree(Path start, FileVisitor super Path> visitor); * ͨ¹ý×Ô¼ºÊµÏÖ FileVisitor À´Íê³É±éÀúÖ¸¶¨µÄĿ¼,µÝ¹é, Path walkFileTree(Path start, Set options,int maxDepth,FileVisitor super Path> visitor) * ͬÉÏ,¶àÒ»¸ö maxDepth À´ÏÞÖÆ±éÀúµÄ²ã´Î * options À´¾ö¶¨ÊÇ·ñÒª¸ú×ÙÁ¬½Ó //=======================¸´ÖÆ long copy(Path path,OutputStream in); * ¸´ÖÆ Path µ½inÁ÷ Path copy(InputStream in,Path target,CopyOption... options); * ¸´ÖÆ in ÖеÄÊý¾Ýµ½ target Path copy(Path source, Path target, CopyOption... options) * ¸´ÖÆ source µ½ target * CopyOption Ö¸¶¨¸´ÖƵĹæÔò //=======================ÒÆ¶¯ Path move(Path source, Path target, CopyOption... options) * ÒÆ¶¯ source µ½ target //=======================ɾ³ý void delete(Path path); * ɾ³ý,Îļþ²»´æÔÚ»áÅ׳öÒì³£ boolean deleteIfExists(Path path); * Èç¹ûÎļþ´æÔÚ,²ÅÖ´ÐÐɾ³ý //=======================´´½¨(Ŀ¼) Path createDirectory(Path dir, FileAttribute>... attrs) * ´´½¨,³ýÁË×îºóÒ»²ã¿ÉÒÔ²»´æÔÚ,ÆäËûµÄ±ØÐë´æÔÚ,²»È»Òì³£ * ˵°×ÁË,Ö»ÄÜ´´½¨Ò»¼¶Ä¿Â¼ * attrs ±íʾÎļþµÄÊôÐÔ Path createDirectories(Path dir, FileAttribute>... attrs); * Öмä¿ÉÒÔÓжà¸ö²ã¶¼²»´æÔÚ,˵°×ÁË,¿ÉÒÔ´´½¨N¼¶Ä¿Â¼ * attrs ±íʾÎļþµÄÊôÐÔ //=======================´´½¨(Îļþ) Path createFile(Path path, FileAttribute>... attrs); * ´´½¨Îļþ,Èç¹ûÎļþÒѾ­´æÔÚ,ÔòÅ׳öÒì³£ //=======================´´½¨(ÁÙʱÎļþ) Path createTempFile(String prefix,String suffix,FileAttribute>... attrs) * ´´½¨ÁÙʱÎļþ¼Ð * prefix ºÍ suffix ¿ÉÒÔÊÇΪnullµÄ×Ö·û´®¶ù Path createTempFile(Path dir,String prefix,String suffix,FileAttribute>... attrs) * ´´½¨ÁÙʱÎļþ¼Ð,»ùÓÚ dir //=======================´´½¨(ÁÙʱÎļþ¼Ð) Path createTempDirectory(String prefix,FileAttribute>... attrs) * ´´½¨ÁÙʱÎļþ¼Ð Path createTempDirectory(Path dir,String prefix,FileAttribute>... attrs) * ´´½¨ÁÙʱÎļþ¼Ð,»ùÓÚ dir ---------------------------- Files-Options | ---------------------------- CopyOption(½Ó¿Ú) StandardCopyOption REPLACE_EXISTING, //Èç¹ûÄ¿±êÒѾ­´æÔÚ,Ôò¸²¸ÇÄ¿±ê COPY_ATTRIBUTES, //¸´ÖÆÎļþµÄÊôÐÔ ATOMIC_MOVE //Ô­×ÓÐÔ²Ù×÷,ÒªÃ´ÒÆ¶¯³É¹¦,ҪôÎļþ»¹ÔÚÔ­´¦ OpenOption(½Ó¿Ú) StandardOpenOption(ö¾Ù) READ, //´ò¿ªÔĶÁȨÏÞ WRITE, //´ò¿ªÐ´È¨ÏÞ APPEND, //ÔÚĩβÌí¼Ó,²»¸²¸ÇÒÔǰµÄÊý¾Ý TRUNCATE_EXISTING, //Èç¹ûÎļþÒѾ­´æÔÚ£¬²¢ÇÒ´ò¿ª½øÐÐWRITE ·ÃÎÊ£¬ÔòÆä³¤¶È½«±»½Ø¶ÏΪ0¡£ CREATE, //Èç¹û²»´æÔÚ,Ôò´´½¨Ð嵀 CREATE_NEW, //´´½¨Ò»¸öеÄÎļþ£¬Èç¹û¸ÃÎļþÒѾ­´æÔÚʧ°Ü¡£ DELETE_ON_CLOSE, //ÔÚjvm¹Ø±ÕµÄʱºòɾ³ýÎļþ SPARSE, //Ï¡ÊèÎļþ SYNC, //ÒªÇó½«ÎļþÄÚÈÝ»òÔªÊý¾ÝµÄÿ´Î¸üж¼Í¬²½Ð´Èëµ×²ã´æ´¢É豸¡£ DSYNC; //ÒªÇó½«ÎļþÄÚÈݵÄÿ´Î¸üж¼Óëµ×²ã´æ´¢É豸ͬ²½Ð´Èë LinkOption * ʵÏÖÀà * 'ʵÏÖÁËOpenOption ºÍ CopyOption' NOFOLLOW_LINKS; FileVisitOption FOLLOW_LINKS ---------------------------- Files-FileAttribute | ---------------------------- # ±íʾÎļþµÄÊôÐÔ½Ó¿Ú,ÐèÒª×Ô¼ºÊµÏÖ×ÓÀà ---------------------------- PosixFilePermission | ---------------------------- # ÎļþȨÏÞö¾ÙÀà * ËùÓÐÕßȨÏÞ OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, * ËùÊô×éȨÏÞ GROUP_READ, GROUP_WRITE, GROUP_EXECUTE, * ÆäËûÈËȨÏÞ OTHERS_READ, OTHERS_WRITE, OTHERS_EXECUTE;