java BufferedWriter 读入文本内容再输出 就是用就Java做一个文本编辑器~
文本编辑器,里面有个打开一个文本文档的功能,怎么样才能让文本文档的内容读写到我的文本编辑器里面?上面的图片是我的代码,求大神帮助修改,能运行的~classOpenFile...
文本编辑器,里面有个 打开一个文本文档的功能,怎么样才能让文本文档的内容读写到我的文本编辑器里面?上面的图片是我的代码,求大神帮助修改,能运行的~
class OpenFile implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
FileDialog d=new FileDialog(MenuWindow.this,"打开文件",FileDialog.LOAD);
d.setVisible(true);
fileName=d.getDirectory()+d.getFile();
BufferedReader bfw = new BufferedReader(new FileReader(fileName));
bfw.write(textArea.getText(),0,textArea.getText().length());
bfw.flush();
bfw.close();
}
catch(Exception e1){}
}
} 展开
class OpenFile implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
FileDialog d=new FileDialog(MenuWindow.this,"打开文件",FileDialog.LOAD);
d.setVisible(true);
fileName=d.getDirectory()+d.getFile();
BufferedReader bfw = new BufferedReader(new FileReader(fileName));
bfw.write(textArea.getText(),0,textArea.getText().length());
bfw.flush();
bfw.close();
}
catch(Exception e1){}
}
} 展开
展开全部
class OpenFile implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
FileDialog d=new FileDialog(MenuWindow.this,"打开文件",FileDialog.LOAD);
d.setVisible(true);
fileName=d.getDirectory()+d.getFile();
BufferedReader bfw = new BufferedReader(new FileReader(fileName));
String line = null;
while((line=bfw.readLine())!=null){
textArea.setText(line+"\n");
}
bfw.flush();
bfw.close();
}
catch(Exception e1){}
}
}
{
public void actionPerformed(ActionEvent e)
{
try
{
FileDialog d=new FileDialog(MenuWindow.this,"打开文件",FileDialog.LOAD);
d.setVisible(true);
fileName=d.getDirectory()+d.getFile();
BufferedReader bfw = new BufferedReader(new FileReader(fileName));
String line = null;
while((line=bfw.readLine())!=null){
textArea.setText(line+"\n");
}
bfw.flush();
bfw.close();
}
catch(Exception e1){}
}
}
2013-05-23
展开全部
BufferedReader 能写文件吗。
BufferedWriter bfw = new BufferedWriter(newFileWriter(fileName));
bfw.write(textArea.getText() );
bfw.flush();
bfw.close();
BufferedWriter bfw = new BufferedWriter(newFileWriter(fileName));
bfw.write(textArea.getText() );
bfw.flush();
bfw.close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询