public static void main(String[] args) { String filePath = "E:/" + "1.txt"; String content = "这是txt文件"; FileWriter fw = null; try { File file = new File(filePath); if (!file.exists()) { file.createNewFile(); } fw = new FileWriter(filePath); fw.write(content); } catch (Exception e) { e.printStackTrace(); } finally { try { fw.close(); } catch (Exception e) { e.printStackTrace(); } } }