beanshell 通过java写数据到文件

import java.io.*;

String filePath = "/data/account.txt"; 
String conent = vars.get("account"); 
BufferedWriter out = null;

try {
   		File file = new File(filePath);
        File fileParent = file.getParentFile();
        if (!fileParent.exists()) { 
         fileParent.mkdirs();
        }
        file.createNewFile();
	out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
	out.write(conent + "\r\n");
} catch (Exception e) {
	e.printStackTrace();
} finally {
	try {
		out.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}

  

posted @ 2019-06-23 17:08  linbo.yang  阅读(485)  评论(0编辑  收藏  举报