- File("e:/1.xml", content);
- //System.out.println(sb);
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- System.out.println("文件不存在!");
- }
- }
- public static void writeFile(String filePathAndName, String fileContent) {
- try {
- File f = new File(filePathAndName);
- if (!f.exists()) {
- f.createNewFile();
- }
- OutputStreamWriter write = new OutputStreamWriter(
- new FileOutputStream(f), "UTF-8");
- BufferedWriter writer = new BufferedWriter(write);
- writer.write(fileContent);
- writer.close();
- } catch (Exception e) {
- System.out.println("写文件内容操作出错");
- e.printStackTrace();
- }
- }
java 读写文件