`

Filenames and Pathnames

阅读更多
俺的java基础不太好,所以每天都要花时间来熟悉java;
将每天学的东西贴上来:
1. Constructing a Filename Path
String path = File.separator + "a" + File.separator + "b";
System.out.println("-----------> "+path);


2.Creating a File
 File file = new File("filename.txt");
 // Create file if it does not exist
boolean success = file.createNewFile();


3.Getting the Size of a File
File file = new File("filename.txt");
// Get the number of bytes in the file
long length = file.length();
System.out.println("length------------->"+length);


4.Renaming a File or Directory
// File (or directory) with old name
	    File file = new File("filename.txt");
	    // File (or directory) with new name
	    File file2 = new File("file.txt");
	    // Rename file (or directory)
	    boolean success = file.renameTo(file2);
	    if (!success) {
	        // File was not successfully renamed
	    }
分享到:
评论

相关推荐

    VclZip pro v3.10.1

    Due to a Delphi strange behavior sometimes path names for directory only entries would become corrupted. Removed reference to QConsts, replaced with RTLConsts. Sometimes a GPF would result if a ...

    VCLZip pro 4.51_1 压缩/解压缩控件(含源码)

    Use Unicode filenames, archive names, and pathnames (except for Delphi/BCB 4 and5) . No Royalties! AES Strong Encryption Zip64 capabilities, properties, methods and events: Uncompressed, ...

    Complete Web Monitoring

    Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, and directories. Constant width Indicates commands, options, switches, variables, attributes, keys, functions, types,...

    convmv-1.15.tar.gz

    Sometimes it might happen that you "double-encoded" certain filenames, for example the file names already were UTF-8 encoded and you accidently did another conversion from some charset to UTF-8....

    Shell.Scripting.Recipes.2nd.Edition.A.Problem-Solution.Approach.148420221X

    Chapter 6: Loose Names Sink Scripts: Bringing Sanity to Filenames Chapter 7: Treading a Righteous PATH Chapter 8: The Dating Game Chapter 9: Good Housekeeping: Monitoring and Tidying Up File Systems ...

    python3.6.5参考手册 chm

    PEP 519: Adding a file system path protocol PEP 495: Local Time Disambiguation PEP 529: Change Windows filesystem encoding to UTF-8 PEP 528: Change Windows console encoding to UTF-8 PEP 520: ...

    Python Cookbook英文版

    4.16 Treating Pathnames as Objects 4.17 Creating Directories Including Necessary Parent Directories 4.18 Walking Directory Trees 4.19 Swapping One File Extension for Another Throughout a ...

    Sakemail

    Because some people need to use IP addresses instead of Host names, I‘ve added a new property IPAddress to SakPOP and SakSMTP. If both are filled, then the Host name will be used, thanks to Roger F. ...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    vim数据库插件dbext_420

    the binary will complain since it does not understand Unix path names. Added the option g:dbext_default_use_win32_filenames which allows you to indicate the binaries must use translated Windows ...

    Python Cookbook, 2nd Edition

    Sorting Names and Separating Them by Initials Chapter 6. Object-Oriented Programming Introduction Recipe 6.1. Converting Among Temperature Scales Recipe 6.2. Defining Constants Recipe 6.3. ...

    edjpgcom|图片中插入一句话

    * Make sure the "Short Names", "multiple files" and DDE are NOT checked. Now you will have an icon on your toolbar and a menu item on the right-click popup window for image files. Template File ---...

    OutlookAttachView v2.73

    path in now delimited with quotes, to ensure that it'll be scanned properly if the folder name contains a comma character. * Version 1.81 o Fixed a crash problem when trying to save outlook ...

    BURNINTEST--硬件检测工具

    Windows 98 and ME are not supported in BurnInTest version 5.3 and above. Use a version of BurnInTest prior to 5.2 for compatibility with W98 and ME. Windows 95 and Windows NT =======================...

    eac3to V3.17

    * fixed: adding subtitle caption count to filenames sometimes didn't work * fixed: subtitle caption counts in log sometimes had wrong track numbers * fixed: all non-supported MKV tracks shared the ...

    php.ini-development

    Currently, [PATH=] and [HOST=] sections only work under ; CGI/FastCGI. ; http://php.net/ini.sections ; Directives are specified using the following syntax: ; directive = value ; Directive names are ...

    unix power tools

    1.10 Internal and External Commands...................................................................................................17 ..................................................................

Global site tag (gtag.js) - Google Analytics