首页 > 代码库 > javase 路径问题

javase 路径问题

import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;/** * 路径问题      javase * @author viakiba */public class Io {        public static void main(String[] args) throws Exception {             /*            //绝对路径   E:/Myworks/serializable/src/txt.txt            //InputStream ip = new FileInputStream(new File("E:/Myworks/serializable/src/txt.txt"));            */                        /*             //默认的是工程名路径    eg:  E:\工作空间\工程名\  E:\Myworks\serializable\src\txt.txt            //InputStream ip = new FileInputStream("src/txt.txt");            */                        /*            //E:\Myworks\serializable\txt.txt            //System.out.println((new File("txt.txt")).getAbsolutePath());                        //E:\txt.txt            //System.out.println((new File("/txt.txt")).getAbsolutePath());            //System.out.println((new File("src/txt.txt")).getAbsolutePath());                        */                                                /*            //系统根路径  ”/“               File f2 = new File("/.").getAbsoluteFile();            String[] list = f1.list();            for(int i=0;i<list.length;i++){                System.out.println(list[i].toString());            }            System.out.println(f2.getAbsolutePath());                        //路径拼接            String path1 = f2.getPath();            System.out.println(new File(path1,"txt.txt").getAbsoluteFile());            */                                    /*            // “//..” 系统根路径的上一级            File f2s = new File("//..").getAbsoluteFile();                        //默认工程的根路径            File f3 = new File("txt.txt").getAbsoluteFile();            System.out.println(f3.getAbsolutePath());            */                        //clazz 放在生成的class文件所在的目录下  建议使用            InputStream ip = Io.class.getResourceAsStream("txt.txt");                        byte[] b = new byte[1024];            int len;            while( (len = ip.read(b)) != -1){                System.out.println( new String(b,0,b.length) );                System.out.println("=====================");            }        }}

 

javase 路径问题