日期:2014-05-20 浏览次数:20713 次
import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; public class Test { public static void main(String[] args) { //文件所在目录 File f = new File("F:/workspace/projects/src/test.txt"); try { OutputStreamWriter write = new OutputStreamWriter( new FileOutputStream(f), "UTF-8"); BufferedWriter writer = new BufferedWriter(write); //替换值 writer.write("1"); writer.close(); } catch (Exception e) { e.printStackTrace(); } } }
------解决方案--------------------
调用系统命令输出重定向,比如 echo 1 > 文件
Runtime.getRunTime().exec("echo 1 > test.txt"); //LZ自己把test.txt的路径补全吧