FileStream测试报错,找不到哪里错,帮忙看一下。 [code=Java][/code] package com.filewriter; import java.io.*; public class FileWriter {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File f = new File("new.txt"); try{ FileWriter fw = new FileWriter(f); //The constructor FileWriter(File) is undefined fw.write("www.baidu.com"); //The method write(String) is undefined for the type FileWriter fw.close(); //The method close() is undefined for the type FileWriter }catch(Exception e){ e.printStackTrace(); } try{ FileReader fr = new FileReader(f); char[] c = new char[1024]; int len = fr.read(c); System.out.println(new String(c,0,len)); }catch(Exception e){ e.printStackTrace(); }
public static void main(String[] args) {
// TODO Auto-generated method stub
File f = new File("new.txt");
try {
java.io.FileWriter fw = new java.io.FileWriter(f); // The
// constructor
// FileWriter(File) is undefined
fw.write("www.baidu.com"); // The method write(String) is undefined
// for the type FileWriter
fw.close(); // The method close() is undefined for the type
// FileWriter
} catch (Exception e) {
e.printStackTrace();
}
try {
FileReader fr = new FileReader(f);
char[] c = new char[1024];
int len = fr.read(c);
System.out.println(new String(c, 0, len));
} catch (Exception e) {
e.printStackTrace();
}
}
------解决方案--------------------