ReadTxtFile this.getClass().getResourceAsStream("/ming.txt");

原创 2012年03月24日 10:14:49
import java.io.*;
class ReadTxt
{
	public void ReadTxtFile()
	{
		String temp="";
		BufferedReader br=null;
		InputStream in = this.getClass().getResourceAsStream("/ming.txt");
		if(in != null)
		{
			br = new BufferedReader(new InputStreamReader(in));
			try{
				while((temp = br.readLine()) != null){
					System.out.println(temp); 
				}
				br.close();
			}catch(Exception e) {
				e.printStackTrace();
			}
			
		}
	}
}

public class TestFile2
{
	/*
getClass().getResource("/ming.txt")	
	*/
/*
Reader reader =new InputStreamReader(  
  getClass().getResourceAsStream("/ming.txt"));
*/

public static void main(String[] args) throws IOException
{
	/*
	FileReader fr = new FileReader(getClass().getResource("/ming.txt"));
	char[] buffer = new char[1024];
	int ch = 0;
	while((ch = fr.read())!=-1 )
	{
		System.out.print((char)ch); 
	}  
	InputStreamReader isr = new InputStreamReader(new FileInputStream(getClass().getResource("/ming.txt")));
	while((ch = isr.read())!=-1)
	{
		System.out.print((char)ch); 
	}  
	BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getClass().getResource("/ming.txt"))));
	String data = null;
	while((data = br.readLine())!=null)
	{
		System.out.println(data); 
	}  
	*/
	ReadTxt Tr=new ReadTxt();
	Tr.ReadTxtFile();

	FileWriter fw = new FileWriter("hello.txt");
	String s = "hello world";
	fw.write(s,0,s.length());
	fw.flush();  
	OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("hello2.txt"));
	osw.write(s,0,s.length());
	osw.flush();  
	PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt")),true);
	pw.println(s);
	/*
	fr.close();
	isr.close();
	br.close();
	*/
	fw.close();
	osw.close();
	pw.close();
} 
}

ReadTxtFile this.getClass().getResourceAsStream("/ming.txt");

import java.io.*; class ReadTxt { public void ReadTxtFile() { String temp=""; BufferedReader b...

this.getClass().getResourceAsStream()读入数据

http://blog.sina.com.cn/s/blog_8af106960102v629.html http://imsnoweagle.blog.sohu.com/108...

getClass().getResourceAsStream() .

src(源文件夹) ┃ ┣━11.properties ┃ ┗━myspider(myspider包)          ┃          ┣━22.properties      ...

abercrombie online pipe Ming Fu also use this approach to fool other people

,abercrombie online it seems less like C leadership,air jordan pas cher, will not be a mistake Not ...

this.class.getClassLoader().getResourceAsStream(path)

相信很多写过web项目的会对this.this.class.getClassLoader().getResourceAsStream(path)这段代码有疑惑。我们用这段代码可以获取在classpat...

this.class.getClassLoader().getResourceAsStream

this.class.getClassLoader().getResourceAsStream 博客分类:  java知识点   this.getClass().getCl...

Java 关于类型类、this.getClass()的理解

import java.io.*; import java.util.*; class test { public static void main (String[] args) throws...

Java在不同环境下获取当前路径的方法--this.getClass().getResource("")

1. 在Servlet/Filter等Servlet web环境中,只要获得javax.servlet.ServletContext类型,则可以通过 getRealPath("...") 获得路径。相...

this.getClass().getClassLoader().getResource("");

调用对象的getClass()方法是获得对象当前的类类型,这部分数据存在方法区中。         类类型上调用getClassLoader()方法是得到当前类型的类加载器。         我们知道...

super.getClass()与this.getClass()的问题

super.getClass()和this.getClass()
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ReadTxtFile this.getClass().getResourceAsStream("/ming.txt");
举报原因:
原因补充:

(最多只允许输入30个字)