import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class RAWFile {
* 写文件
*/
public static void writeFile( File Wfile) throws FileNotFoundException
{
System.out.println("保存文件...");
if(Wfile.exists())
Wfile.delete();
FileOutputStream fout=new FileOutputStream(Wfile);
PrintWriter pWriter=new PrintWriter(fout);
pWriter.println("重复聚类次数:");
pWriter.println("重复聚类次数:");
pWriter.println("重复聚类次数:");
pWriter.println("重复聚类次数:");
pWriter.println("重复聚类次数:");
//这里很重要,要不然就写不到文件里。
pWriter.flush();
pWriter.close();
}
public static void readFile(File Rfile) throws IOException
{
if(!Rfile.exists())
{
System.out.println("要读的文件不存在!");
System.exit(-1);
}
FileInputStream fin=new FileInputStream(Rfile);
BufferedReader reader=new BufferedReader(new InputStreamReader(fin));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line = reader.readLine();
}
}
public static void main(String[] args)throws IOException {
//写文件,是从内存住硬盘文件里写入内容
//用文件输出流(FileOutputStream)
File Wfile=new File("write.txt");
writeFile(Wfile);
//读文件,是从硬盘文件往内存里写,也叫读文件
//用文件输入流(FileInputStrea),读缓冲(BufferedReader)
//读出刚才写的文件;
File Rfile = Wfile ;
readFile(Rfile);
}