java求大神帮忙对一个小程序注释 100
publicvoidWriteRecord(){Stringcontent;content=CenterText.getText();intn=content.lengt...
public void WriteRecord()
{
String content;
content=CenterText.getText();
int n=content.length();
char[] contentarr=new char[n];
try
{
int i=0;
for(i=0;i<n;i++)
{
contentarr[i]=content.charAt(i);
}
File Diary = new File("Diary");
Diary.mkdir();
File myfile=new File("Diary\\"+key+".txt");
FileWriter Record=new FileWriter(myfile);
for(i=0;i<contentarr.length;i++)
{
Record.write(contentarr[i]);
}
Record.close();
JOptionPane.showMessageDialog(this,"保存成功!");
}
catch(IOException ex)
{
}
}
public void ReadRecord()
{
try
{
String content="";
File myfile=new File("Diary\\"+key+".txt");
FileReader Record=new FileReader(myfile);
if(myfile.exists())
{
long b=myfile.length();
int n=JOptionPane.showConfirmDialog(this,"查看今天日程?","确定",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
while((b=Record.read())!=-1)
{
content=content+(char)b;
}
CenterText.setText(content);
}
}
Record.close();
}
catch(IOException ex)
{
CenterText.setText("今天没有日程。");
}
}
public void DeleteFile()
{
String filepath="Diary\\"+key+".txt";
File myfile=new File(filepath);
int n=JOptionPane.showConfirmDialog(this,"确定删除?","确定",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
if(myfile.exists())
{
Runtime rt = Runtime.getRuntime();
try
{
rt.exec("cmd /c del "+filepath);
}
catch (IOException e)
{
e.printStackTrace();
}
JOptionPane.showMessageDialog(this,"删除成功!");
CenterText.setText("今天没有日程。");
}
else
{
JOptionPane.showMessageDialog(this,"文件不存在,删除失败!");
}
}
} 展开
{
String content;
content=CenterText.getText();
int n=content.length();
char[] contentarr=new char[n];
try
{
int i=0;
for(i=0;i<n;i++)
{
contentarr[i]=content.charAt(i);
}
File Diary = new File("Diary");
Diary.mkdir();
File myfile=new File("Diary\\"+key+".txt");
FileWriter Record=new FileWriter(myfile);
for(i=0;i<contentarr.length;i++)
{
Record.write(contentarr[i]);
}
Record.close();
JOptionPane.showMessageDialog(this,"保存成功!");
}
catch(IOException ex)
{
}
}
public void ReadRecord()
{
try
{
String content="";
File myfile=new File("Diary\\"+key+".txt");
FileReader Record=new FileReader(myfile);
if(myfile.exists())
{
long b=myfile.length();
int n=JOptionPane.showConfirmDialog(this,"查看今天日程?","确定",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
while((b=Record.read())!=-1)
{
content=content+(char)b;
}
CenterText.setText(content);
}
}
Record.close();
}
catch(IOException ex)
{
CenterText.setText("今天没有日程。");
}
}
public void DeleteFile()
{
String filepath="Diary\\"+key+".txt";
File myfile=new File(filepath);
int n=JOptionPane.showConfirmDialog(this,"确定删除?","确定",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
if(myfile.exists())
{
Runtime rt = Runtime.getRuntime();
try
{
rt.exec("cmd /c del "+filepath);
}
catch (IOException e)
{
e.printStackTrace();
}
JOptionPane.showMessageDialog(this,"删除成功!");
CenterText.setText("今天没有日程。");
}
else
{
JOptionPane.showMessageDialog(this,"文件不存在,删除失败!");
}
}
} 展开
1个回答
2016-06-22
展开全部
这个是数据结构的基础,建议基础的东西还是自己解决,也就会这么一两天时间就能学会这几种排序的精髓。少在别的方面花一两天时间多用在学习上,将来毕业少走很多弯路。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询