Java's file object to the operation of the files commonly used several methods (recommended) _mssql2008

Source: Internet
Author: User
Tags file size

File object is the most commonly used class of files, usually work a lot, posted a few I work commonly used several methods. Briefly summed up the next

Directly on the code:

The build file Object file File=new file ("e:/android_demo/a");

File Filetest=new file ("E:/android_demo/a/test.mp3");
Gets the file's parent path file F=file.getparentfile (); System.out.println ("f==" +f);//e:\android_demo//Judge whether the file exists a Boolean is=file.exists ();//does not exist, returns Fasle System.out.println

("is==" +is);
Getting the absolute path of a file can be understood as equivalent to GetPath String Path1=file.getabsolutepath ();
System.out.println ("path==" +path1);//e:\android_demo\a//Get file path String Path2=file.getpath ();
System.out.println ("path2==" +path2);//e:\android_demo\a//get current filename String s=file.getname ();

System.out.println ("s===" +s);

Create a folder, namely: e:/android_demo/a File.mkdir ();
Create a file, namely: E:/android_demo/a/test.mp3 Filetest.createnewfile ();
File size, the number of bytes occupied by the file when it was stored; long l=f.length ();

System.out.println ("l==" +l);
Gets the file path string string str=filetest.tostring (); System.out.println ("str==" +str);//E:\android_demo\a\test.mp3 to rename file filetest2=new files ("e:/android_demo/a/
Test2.mp3 ");
Boolean B2=filetest.renameto (FILETEST2); System.out.println ("b2==" +b2);//e:/android_demo/A/test2.mp3//Delete file Boolean b3=filetest.delete (); Delete the folder, note that the deleted folder must have no files to delete, some words to facilitate the deletion of all files, and then delete the Boolean b4=file.delete ();

Above this Java file object to the operation of a number of common methods (recommended) is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

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.