怎么让这个简单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
展开
全部