给你一段读文件写文件的代码,自己再悟悟看。不知道你删除的定义格式,没法写。
private static String readInput(String strFN)
throws FileNotFoundException, IOException
{
FileInputStream fis = new FileInputStream(strFN);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
String line = br.readLine();
if (line == null)
return new String();
else
sb.append(line);
while ((line = br.readLine()) != null)
sb.append("\n" + line);
br.close();
return sb.toString();
} private static void writeOutput(String strFN, String str)
throws FileNotFoundException, IOException
{
FileOutputStream fos = new FileOutputStream(strFN);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
BufferedWriter bw = new BufferedWriter(osw); StringReader sr = new StringReader(str);
BufferedReader br = new BufferedReader(sr); String line = br.readLine();
if (line != null)
bw.write(line);
while ((line = br.readLine()) != null)
{
bw.newLine();
bw.write(line);
}
bw.flush();
bw.close();
br.close();
}