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

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();
} 
}

阅读更多
个人分类: Java笔记
上一篇CSemaphore semaphoreWrite(2,2);
下一篇CFile f; CFileException e; if(!f.Open(pFileName,CFile::modeRead...
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭