package cn.mypic;
import java.io.*;
public class FileNumber{
//文件写
public void NumberWriteToFile(int x){
int c=0;
c=x;
File filePath=new File("d:/image");//文件名序号TXT文件保存地址
File f1=new File(filePath,"number.txt");
try{
FileOutputStream fout=new FileOutputStream(f1);
DataOutputStream out=new DataOutputStream(fout);
out.writeInt(c);
}
catch(FileNotFoundException e){
System.err.println(e);
}
catch(IOException e){
System.err.println(e);
}
}
//文件读
public int NumberReadFromFile(){
int c1 = 0;
File filePath=new File("d:/image");
File f1=new File(filePath,"number.txt");
try{
FileInputStream fin=new FileInputStream(f1);
DataInputStream in=new DataInputStream(fin);
c1=in.readInt();
System.out.println(c1);//输出文件内容至屏幕
}
catch(FileNotFoundException e){
System.err.println(e);
}
catch(IOException e){
System.err.println(e);
}
return c1;
}
public static void main(String args[]){
}
}