首页 > 代码库 > Java读取TXT文本

Java读取TXT文本

public String readTxtFile(String filePath) {		StringBuffer appInfolistInput = new StringBuffer();		try {			String encoding = "UTF8";			File file = new File(filePath);			if (file.isFile() && file.exists()) {				InputStreamReader read = new InputStreamReader(						new FileInputStream(file), encoding);				BufferedReader bufferedReader = new BufferedReader(read);				String lineTxt = null;				while ((lineTxt = bufferedReader.readLine()) != null) {					appInfolistInput.append(lineTxt);				}				read.close();				bufferedReader.close();			} else {				System.out.println("找不到指定的文件");			}		} catch (Exception e) {			System.out.println("读取文件内容出错");			e.printStackTrace();		}		return appInfolistInput.toString();	}

 

Java读取TXT文本