天天看點

java的讀寫檔案IO操作

1、FileInputStream讀檔案操作:

    public static void main(String[] args){

        InputStream file=null;

        try{

            file=new FileInputStream(xsdPath);

            int len=0;

            byte[] buf = new byte[1024];

            while((len=file.read(buf))!=-1){

                System.out.println(new String(buf, 0 , len));

            }

        } catch(Exception e){

            // TODO Auto-generated catch block

            e.printStackTrace();

        }finally {

            if (file!= null) {

                try {

                    file.close();

                } catch (IOException e) {

                    //exception;

                }

            }

        }

    }