package cn.liwenjun.sfile;import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;public class readfile { /**
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String name="C:\\bsmain_runtime.log";//随便一个文件想在控制台上打印这个文件的内容
// readfile1(name);
// readfile2(name);
// readfile3(name);
// readfile4(name);
// readfile5(name);
readfile6(name);
}
public static void readfile1(String name) throws IOException{
//1.使用java.util.Properties类的load()方法 
System.out.print("第1个方法"); 
InputStream in = new BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();   
p.load(in);
System.out.print(p);
}
public static void readfile2(String name) throws IOException{
//2.使用java.util.ResourceBundle类的getBundle()方法
System.out.print("第2个方法"); 
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault()); }
public static void readfile3(String name) throws IOException{
//3.使用java.util.PropertyResourceBundle类的构造函数 
System.out.print("第3个方法");
InputStream in = new BufferedInputStream(new FileInputStream(name));   
ResourceBundle rb = new PropertyResourceBundle(in);   }
public static void readfile4(String name) throws IOException{
//4.使用class变量的getResourceAsStream()方法
System.out.print("第4个方法");
InputStream in = JProperties.class.getResourceAsStream(name);   
Properties p = new Properties();   
p.load(in);   
}
public static void readfile5(String name) throws IOException{
//5.使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法 
System.out.print("第5个方法");
InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);   
Properties p = new Properties();   
p.load(in);   }
public static void readfile6(String name) throws IOException{
//6.使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法 
System.out.print("第6个方法"); 
InputStream in = ClassLoader.getSystemResourceAsStream(name);   
Properties p = new Properties();   
p.load(in);    }}