拿到的第一个任务的要求,结果最后又不用了。扔了怪可惜的,就留着看看吧。
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.StringReader; /** * 将相应的信息写入XML文件 * * @author wyd * */ public class XMLWriter { public void writeStringFile(String Data,String filePath) { BufferedReader bufferedReader = null; BufferedWriter bufferedWriter = null; File distFile = null; try { distFile = new File(filePath); if (!distFile.getParentFile().exists()) distFile.getParentFile().mkdirs(); bufferedReader = new BufferedReader(new StringReader(Data)); bufferedWriter = new BufferedWriter(new FileWriter(distFile)); char buf[] = new char[1024]; // 字符缓冲区 int len; while ((len = bufferedReader.read(buf)) != -1) { bufferedWriter.write(buf,len); } bufferedWriter.flush(); bufferedReader.close(); bufferedWriter.close(); } catch (Exception e) { writeStringFile(Data,filePath); } } }原文链接:https://www.f2er.com/xml/299419.html