ReadTxtFile

package file;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 
 * 
 *
 * @author ZengWenfeng
 * @email [email protected]
 * @date 2012.04.12
 */
public class ReadTxtFile
{
	/*
	 * 讀文件
	 */
	public static void readTxt()
	{
		// 文件和該類在同個目錄下
		String filePath = TextCharset.class.getResource("").getPath().replace("file:", "") + "/1.txt";
		BufferedReader reader = null;
		try
		{
			// 指定讀取文件的編碼格式,要和寫入的格式一致,以免出現中文亂碼
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
			String str = null;
			while ((str = reader.readLine()) != null)
			{
//				System.out.println(str);
				//sql.append(" WHERE 1 = 1 ");
				System.out.println("sql.append(\" " + str + " \");");
			}
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				reader.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args)
	{
		readTxt();
	}

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章