all = String.valueOf(num) +" , "+
name +" , "+
sex +" , "+
String.valueOf(mark);//把所有的数据用" , "隔开然后在连起来放进字符串all
}catch (IOException e){}
catch (NumberFormatException e){}
return all;//返回字符串all
}
public void addData(String str)//增加数据的方法
throws IOException
{
String s1 ="",s2="" ,s3= "";
File file = new File("data.txt");
if (file.exists())//如果文件data.txt存在
{
try{
BufferedReader in =
new BufferedReader(
new FileReader("data.txt"));
while ((s1=in.readLine())!=null)
s2+=s1+"\n";//把文件中的每行数据全部放进一个字符串s2
s2+=str+"\n"; //再把s2于形参str相连放进s2
BufferedReader in2 = //把字符
new BufferedReader( //串s2也
new StringReader(s2)); //就是原
PrintWriter out = //文件+
new PrintWriter( //形参str(新输入的一行数据)
new BufferedWriter( //重新写进data.txt
new FileWriter("data.txt"))); //覆盖原来的数据
while ((s3=in2.readLine())!= null)
{
out.println(s3);
}
out.close();
//System.out.println("write data true.");
}catch (IOException e){}
}else{
System.err.println("File \"data\" Missing!");
}
}
public void clearData()//清除data.txt的所有数据的方法
throws IOException
{
File file = new File("data.txt");
if(file.exists())//如果文件在
{
try{
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
out.print("");//在文件data.txt里写进一个空字符,所以清除了原来的内容
out.close(); //关闭文件
System.out.println("clear data true!");
}catch(IOException e){}
}else{
System.err.println("File \"data\" Missing!");
}
}
public void deleteData(long deleteNumber)//删除某条数据
throws IOException,FileNotFoundException
{
isDelete = true;
try{
DataMap mp = new DataMap();//生成一个自己编写的容器
long j=0;
String s1="",s2="",s3="";
BufferedReader in =
name +" , "+
sex +" , "+
String.valueOf(mark);//把所有的数据用" , "隔开然后在连起来放进字符串all
}catch (IOException e){}
catch (NumberFormatException e){}
return all;//返回字符串all
}
public void addData(String str)//增加数据的方法
throws IOException
{
String s1 ="",s2="" ,s3= "";
File file = new File("data.txt");
if (file.exists())//如果文件data.txt存在
{
try{
BufferedReader in =
new BufferedReader(
new FileReader("data.txt"));
while ((s1=in.readLine())!=null)
s2+=s1+"\n";//把文件中的每行数据全部放进一个字符串s2
s2+=str+"\n"; //再把s2于形参str相连放进s2
BufferedReader in2 = //把字符
new BufferedReader( //串s2也
new StringReader(s2)); //就是原
PrintWriter out = //文件+
new PrintWriter( //形参str(新输入的一行数据)
new BufferedWriter( //重新写进data.txt
new FileWriter("data.txt"))); //覆盖原来的数据
while ((s3=in2.readLine())!= null)
{
out.println(s3);
}
out.close();
//System.out.println("write data true.");
}catch (IOException e){}
}else{
System.err.println("File \"data\" Missing!");
}
}
public void clearData()//清除data.txt的所有数据的方法
throws IOException
{
File file = new File("data.txt");
if(file.exists())//如果文件在
{
try{
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
out.print("");//在文件data.txt里写进一个空字符,所以清除了原来的内容
out.close(); //关闭文件
System.out.println("clear data true!");
}catch(IOException e){}
}else{
System.err.println("File \"data\" Missing!");
}
}
public void deleteData(long deleteNumber)//删除某条数据
throws IOException,FileNotFoundException
{
isDelete = true;
try{
DataMap mp = new DataMap();//生成一个自己编写的容器
long j=0;
String s1="",s2="",s3="";
BufferedReader in =
| 对此文章发表了评论 |
