`

java写入txt文件

    博客分类:
  • java
阅读更多
File file = new File("d:/Data.txt");
		if (!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
				return;
			}
		}
		OutputStreamWriter os = null;
		try {
			os = new OutputStreamWriter(new FileOutputStream(file, true));
			for (String key : map.keySet()) {
				String property = map.get(key);
				os.write(property);
				os.write("\t");
				os.write(key);
				os.write("\r\n");
			}
			os.write("==========");
			os.write("\r\n");
			os.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics