`

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, ...

    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....

    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: ...

    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 ...

    c和汇编手册 英文版

    - **Specifying Filenames and Directories**: 指定源文件、头文件、库文件等的位置,以及输出文件的保存目录。 - **Changing How the Compiler Processes C Files**: 控制编译器如何处理C语言文件,如预处理指令...

    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 ...

    SPRU514P-TMS320C28x Optimizing CC++ Compiler.pdf

    预处理器(Preprocessor)的控制部分介绍了预定义宏(Predefined Macro Names)的使用、头文件的搜索路径(The Search Path for #include Files)、对#warning和#warn指令的支持,以及如何生成预处理列表文件...

Global site tag (gtag.js) - Google Analytics