Intellij IDEA15:加载resources文件

Intellij IDEA15:加载resources文件_第1张图片


package com.donews.staticlog;


import java.io.BufferedInputStream;
import java.io.InputStream;
/**
 * Created by silentwolf on 2016/5/17.
 */
public class loadfile {

    public static void main(String[] argv) {
        try {
            InputStream is=loadfile.class.getClassLoader().getResourceAsStream("data.txt");

            BufferedInputStream bis = new BufferedInputStream(is);

            byte[] arr = new byte[1024*8];

            int len;

            while((len=bis.read(arr))!=-1) {

                System.out.println(new String(arr,"utf8"));

            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

}




你可能感兴趣的:(【工,具】工具类)