首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

读写txt资料

2012-09-16 
读写txt文件读取txt文件:/** * 读取txt文件的整行 * @return * @throws IOException */public ListString

读写txt文件

读取txt文件:

/** * 读取txt文件的整行 * @return * @throws IOException */public List<String> read(String fileName) throws IOException {List<String> txtList = new ArrayList<String>();BufferedReader in = new BufferedReader(new FileReader(fileName));String line = null;while ((line = in.readLine()) != null) {txtList.add(line);}return txtList;}

?写入txt文件:

/** * 将"Hello world!"写入txt文件("Hello world!"可以换为字符串) * @param fileName txt文件路径 */public void writeTpTxt(String fileName) {try {File file = new File(fileName);FileWriter fw = new FileWriter(file);BufferedWriter bw = new BufferedWriter(fw);bw.write("Hello world!");bw.close();} catch (IOException e) {e.printStackTrace();}}
?

?

热点排行