Constructing a file object with relative paths and absolute paths

Source: Internet
Author: User

Package File;import Java.io.file;public class FileTest1 {public static void main (string[] args) {//TODO auto-generated Me Thod stub/* just establish a connection with this file, not to see if the file exists */string parentpath= "E:/backup"; String name= "Expdat. DMP ";//Use relative path to build file Object file Src=new file (parentpath,name);//file (file parent,string child)  // Creates a new file object based on the parent abstract pathname and child pathname string file Src1=new file (parentpath), name),//file (String parent,string Child)  /////Create a new File Object System.out.println (Src.getname ()) based on the parent pathname string and the child pathname string;//file (string parent)// The absolute path to build files file src2=new ("E:/backup/2.jpg"); System.out.println (Src2.getpath ());//File Src3=new file ("2.jpg") without a drive letter; System.out.println (Src3.getpath ()); System.out.println (Src3.getabsolutepath ()); }}

  

Run results

Expdat. DMPE:\BACKUP\2.JPG2.JPGF:\J2EE Operation \tt\2.jpg

  

Constructing a file object with relative paths and absolute paths

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.