知乎专栏 |
import java.io.*; public class Main { public static void main(String[] args) { try { String str = "SomeMoreTextIsHere"; File newTextFile = new File("thetextfile.txt"); FileWriter fw = new FileWriter(newTextFile); fw.write(str); fw.close(); } catch (IOException iox) { //do stuff with exception iox.printStackTrace(); } } }