- Java code
String filePath = "C://test.doc"; File file = new File(filePath); try{ if(!file.exists()) file.createNewFile(); FileWriter fw = new FileWriter(new File(file);//创建文件字符输出流 BufferedWriter bw = new BufferedWriter(fw);
显示错误为The constructor FileOutputStream(File) is undefined
------解决方案--------------------
- Java code
import java.io.File;import java.io.FileOutputStream;public class Test1 { public static void main(String[] args) { File file = new File("C:/","word.txt"); try{ if(!file.exists()){ file.createNewFile(); //如果文件不存在,则创建新文件 } FileOutputStream out = new FileOutputStream(file); byte buy[] ="java编程宝典,程序员的黄金搭档".getBytes(); //创建byte型数组 out.write(buy); //将数组的信息写入文件中 out.close(); }catch(Exception e){ e.printStackTrace(); } }}