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[]){
}
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论