标签:.com bytes 分享 code ace dem demo 相对 路径
输出文件的长度
1 import java.io.File; 2 3 public class PathDemo01 { 4 public static void main(String[] args) { 5 String path = "E:/Java/workspace/IO_Study01/StarSky.jpg"; 6 7 File src = new File(path); 8 System.out.println(src.length() + " bytes"); 9 10 src = new File("E:/Java/workspace/IO_Study01", "StarSky.jpg"); 11 System.out.println(src.length() + " bytes"); 12 13 src = new File(new File("E:/Java/workspace/IO_Study01"), "StarSky.jpg"); 14 System.out.println(src.length() + " bytes"); 15 } 16 }
注意图片的位置,以及java文件的位置
绝对路径 & 相对路径???
1 import java.io.File; 2 3 public class PathDemo01 { 4 public static void main(String[] args) { 5 File src; 6 7 // Absolute path 8 src = new File("E:/Java/workspace/IO_Study01/StarSky.jpg"); 9 System.out.println("Absolute path: " + src.getAbsolutePath()); 10 System.out.println("Parent directory: " + src.getParent()); 11 System.out.println("----------------------------------------"); 12 13 // Relative path 14 System.out.println(System.getProperty("user.dir")); 15 src = new File("StarSky.jpg"); 16 System.out.println("Absolute path: " + src.getAbsolutePath()); 17 System.out.println("Parent directory: " + src.getParent()); 18 } 19 }
标签:.com bytes 分享 code ace dem demo 相对 路径
原文地址:https://www.cnblogs.com/Satu/p/9898184.html