Java I/O (1)

Source: Internet
Author: User

         File f =  new File( "d:/LOLFolder/LOL.exe" );          System.out.println( "当前文件是:" +f);          //文件是否存在          System.out.println( "判断是否存在:" +f.exists());                   //是否是文件夹          System.out.println( "判断是否是文件夹:" +f.isDirectory());                    //是否是文件(非文件夹)          System.out.println( "判断是否是文件:" +f.isFile());                    //文件长度          System.out.println( "获取文件的长度:" +f.length());                    //文件最后修改时间          long time = f.lastModified();          Date d =  new Date(time);          System.out.println( "获取文件的最后修改时间:" +d);          //设置文件修改时间为1970.1.1 08:00:00          f.setLastModified( 0 );                    //文件重命名          File f2 = new File( "d:/LOLFolder/DOTA.exe" );          f.renameTo(f2);          System.out.println( "把LOL.exe改名成了DOTA.exe" );    // 以字符串数组的形式,返回当前文件夹下的所有文件(不包含子文件及子文件夹)          f.list();            // 以文件数组的形式,返回当前文件夹下的所有文件(不包含子文件及子文件夹)          File[]fs= f.listFiles();            // 以字符串形式返回获取所在文件夹          f.getParent();            // 以文件形式返回获取所在文件夹          f.getParentFile();          // 创建文件夹,如果父文件夹skin不存在,创建就无效          f.mkdir();            // 创建文件夹,如果父文件夹skin不存在,就会创建父文件夹          f.mkdirs();            // 创建一个空文件,如果父文件夹skin不存在,就会抛出异常          f.createNewFile();          // 所以创建一个空文件之前,通常都会创建父目录          f.getParentFile().mkdirs();            // 列出所有的盘符c: d: e: 等等          f.listRoots();            // 刪除文件          f.delete();            // JVM结束的时候,刪除文件,常用于临时文件的删除          f.deleteOnExit();When there is data interaction between different media, Java uses a stream to implement it.
The data source can be a file, a database, a network, or even other programs


such as reading the file data into the program, from the point of view of the program, is called the input stream
Input stream: InputStream
Output stream: OutputStream recommendations for the closure of a flow in the finally or try () this is a technique called try-with-resources, which starts with support from JDK7. There are several coding methods that are often contacted:
iso-8859-1 ASCII digits and western European alphabet
GBK GB2312 BIG5 Chinese
UNICODE (Uniform Code, Universal Code) cache character input stream BufferedReader can read one row of data at a timeprintwriter cache character output stream, can write one row of data at a timeSometimes it is necessary to write the data to the hard disk immediately, instead of waiting until the cache is full. This is where flush is needed .

Java I/O (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.