----------------解决方案--------------------------------------------------------
我拷不会吧
----------------解决方案--------------------------------------------------------
File file = new File("path and file name you want to save");
FileOutputStream fos = new FileOutputStream(file); fos.write(//byte you want to write); fos.close();
或者用FileWriter如果写入的是char流,方便
----------------解决方案--------------------------------------------------------
what i will do is ask the user to specify a path which they want to create the file. The program can be written in a few ways, i.e. using different class, they are gernally three of them, FileWriter, BufferedWriter and PrintWriter, in here i will use PrintWriter, because this is the easiest way.
public class Write{
public static void main(String[] args) throws IOException{
//to use the PrintWriter class which must pass in a FileWriter object as parameter
PrinteWriter pr = new PrintWriter(new FileWriter(agrs[0])); /*args[0] is the first file name specified by the user in the command line, if the file name doesnt exist, it will create a new one*/
pr.println("Whatever you wanna type.");
pr.print("Pretty much the same as using System.out.");
pr.close(); // this is very important
}
}
----------------解决方案--------------------------------------------------------