问题描述
- 使用Template模板生成了脚本后怎么把这个脚本的内容写入到一个txt文件中呢?求大神解答
-
public static void main(String[] args) throws Exception {Map map = new HashMap(); Configuration cfg = new Configuration(); Template t = cfg.getTemplate("src/main/webapp/model/sqoop_header.ftl"); t.process(map, new OutputStreamWriter(System.out));
}
执行之后控制台输出脚本如下:
#!/bin/bashCONNECTION="jdbc:oracle:thin:@//10.203.24.110:1521/QA060"
USERNAME="HDPWOL"
PASSWORD="SGM.ORACLE.WOL.HDPWOL.PASSWORD"
CRED_PATH="jceks://hdfs/user/sys_sqoop/password/sgm.oracle.wol.hdpwol.password.jceks"
DIR_PATH="/user/cdh_tmp/sqoop/oracle/wol/"
DATE="/bin/date +%Y%m%d"
SLIPT='01'
MAPCOUNT=4
想把这段内容直接写入到一个txt文件中,这么写:
FileUtils.writeStringToFile(new File("d:/1.txt"), new String(new OutputStreamWriter(System.out).toString()), "utf-8");
结果:txt文件中只有这一句:java.io.OutputStreamWriter@2e7f4425
该怎么写呢?
时间: 2024-10-02 09:31:49