测试

呵呵,这是我的第一个日志。
记录一下,主要是做实验用的,下边先粘贴一段代码,看看效果如何。
 package testfreemarker;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class Test1  {
	public static void main(String[] args) throws Exception{
		//testTemplates();
		testIo();
	}
	
	public static void testTemplates() throws Exception{
		Configuration cfg = new Configuration();
		cfg.setDirectoryForTemplateLoading(new File("templates"));
		
		Map root = new HashMap();
		root.put("user","张三");
		
		Template template1 = cfg.getTemplate("a.ftl");
		
		Writer out = new OutputStreamWriter(System.out);
		template1.process(root, out);
		
		out.flush();
		out.close();
	}
	
	public static void testIo() throws Exception{
		String name = "是sff凤飞d飞凤飞飞度";
		
	//	BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("file/1.file")));
	//	bos.write(name.getBytes());
	//	bos.flush();
	//	bos.close();
		
	//	BufferedWriter bw = new BufferedWriter(new FileWriter(new File("file/1.file")));
	//	bw.write(name);
	//	bw.flush();
	//	bw.close();
		
	//	FileOutputStream fos = new FileOutputStream(new File("file/1.file"));
	//	OutputStreamWriter osw = new OutputStreamWriter(fos);
	//	osw.flush();
	//	osw.close();
		
	//	FileOutputStream fos = new FileOutputStream(new File("file/1.file"));
	//	fos.write(name.getBytes());
	//	fos.flush();
	//	fos.close();
		
	//	FileWriter fw = new FileWriter(new File("file/1.file"), true);  //为true时追加
	//	fw.append("\n");
	//	fw.append("sf");
	//	fw.write(name);
	//	fw.flush();
	//	fw.close();
		
	//	PrintStream ps = new PrintStream(System.out);
	//	ps.write(name.getBytes());
	//	ps.close();
		
	//	PrintStream ps = new PrintStream(new File("file/1.file"));
	//	ps.write(name.getBytes());
	//	ps.close();
		
		PrintWriter pw = new PrintWriter(System.out);
		pw.write(name);
		pw.close();
		
	}
}

你可能感兴趣的:(java)