java中使中文可读_怎么让这个简单JAVA程序读写中文字符

怎么让这个简单JAVA程序读写并正确显示中文字符,现在它只能读写显示英文字符。//这是个简单的读写文本的程序import .*;import t.*;import javax.swing.*;import t.event.*;public class Wel

怎么让这个简单JAVA程序读写并正确显示中文字符,现在它只能读写显示英文字符。//这是个简单的读写文本的程序import .*;import t.*;import javax.swing.*;import t.event.*;public class Welcome extends JFrame implements ActionListener{ private JTextArea ioTextArea; private JButton saveButton,openButton; private JLabel label; private FileInputStream inFile; private FileOutputStream outFile; private File file; byte[] bufferArray=new byte[4096]; public Welcome(){ Container container=getContentPane(); tLayout(new FlowLayout()); label=new JLabel("文本显示及编辑区:"); tForeground( d); d(label,BorderLayout.NORTH); ioTextArea=new JTextArea("",10,20) ; tEditable(true) ; d(new JScrollPane(ioTextArea),BorderLayout.CENTER); saveButton=new JButton("Save") ; d(saveButton,BorderLayout.EAST); dActionListener(this); openButton=new JButton("Open") ; d(openButton,BorderLayout.WEST); dActionListener(this); setSize(300,300); setVisible(true); } public void actionPerformed(ActionEvent event){ if( tSource()==saveButton){ try{ outFile=new FileOutputStream(new File("test.txt")); outFile.write( tText().getBytes(),0, tText().length()); ose(); owMessageDialog(this,"内容已保存到test.txt!"); } catch(IOException e) { owMessageDialog(this,"写入错误!","Error",JOptionPane.ERROR_MESSAGE); System.exit(1); } } else if( tSource()==openButton){ try{ file=new File("test.txt"); int fileLength=(int)file.length(); inFile=new FileInputStream(file); ad(bufferArray,0,fileLength); String str=new String(); for(int i=0;i

展开

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值