应该是系统的问题。
在JTextArea中的换行可能是\r\n
而在txt文件中可能是\n或者相反。。所以你只要自己试着替换一下就可以了

解决方案 »

  1.   

    这很正常,原本是这样的你打其它有回车换行文件(.txt)
    是不是也有一个个的小方框呢!!!!!
      

  2.   

    那个方块是行结束符。
    你用记事本打开就会看到一个方,用word等浏览工具就不会。
    记事本好象不认识此符号,根本不会换行。
      

  3.   

    我的源程序是:
      JTextArea jtFunction=new JTextArea();
      String sFunction=jtFunction.getText();
      File fJsFile=new File(fDir,sFileName);
      fJsFile.createNewFile();
      FileOutputStream fileWrite=new FileOutputStream(fJsFile);
      DataOutputStream dataWrite=new DataOutputStream(fileWrite);
      dataWrite.writeBytes(sFunction);
      

  4.   

    能一能把原文发过来,mail也可以的,[email protected]
    Thank you!
      

  5.   

    // JEnterDemo.java
    // import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;class JEnterDemo extends JFrame
    {
        JEnterDemo(String strTitle) {
            super(strTitle);        openButton.addActionListener(new ActionListener () {
                public void actionPerformed(ActionEvent evt) {
    // open a text file
                    int returnVal = chooser.showOpenDialog(openButton);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File fin = chooser.getSelectedFile();
                        if (fin.exists()) {
                            try
                            {
                                view.setText("");
    // read and display the text content
                                BufferedReader in = new BufferedReader(new FileReader(fin));
                                String strBuffer = null;                            while ((strBuffer = in.readLine()) != null) {
                                    view.append(strBuffer + newline);
                                }
                                in.close();                        
                            }
                            catch (IOException e) {
                            }
                        }
                    }
                }
            });        saveButton.addActionListener(new ActionListener () {
                public void actionPerformed(ActionEvent evt) {
    // save to a file
                    int returnVal = chooser.showSaveDialog(saveButton);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File fout = chooser.getSelectedFile();
                        try {
    // no line separator swaping (\n -> \r\n)
    // so when you open the saved file with notepad, it would be ... :(
    // however, open and save operation is this application is consistent :)
                            BufferedWriter out = new BufferedWriter(new FileWriter(fout));
                            String strBuffer = view.getText();
                            out.write(strBuffer, 0, strBuffer.length());
                            out.flush();
                            out.close();                        
                        }
                        catch (IOException e) {
                        }                }
                }
            });// build UI
            view.setMargin(new Insets(5,5,5,5));
            view.setEditable(true);
            view.setTabSize(4);
            view.setFont(new Font("Courier New", Font.PLAIN, 12));        JPanel contentPane = new JPanel();
            contentPane.setLayout(new BorderLayout());
            contentPane.add(openButton, BorderLayout.NORTH);
            contentPane.add(new JScrollPane(view), BorderLayout.CENTER);
            contentPane.add(saveButton, BorderLayout.SOUTH);
            contentPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
            setContentPane(contentPane);
        } public static void main(String[] args) { 
            JFrame frame = new JEnterDemo("MyApplication");
            try {
                UIManager.setLookAndFeel(
                    UIManager.getCrossPlatformLookAndFeelClassName()
                );
            } catch(Exception e) {
                e.printStackTrace();
            }
            
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);        frame.pack();
            frame.setVisible(true);
    }    private JTextArea view      = new JTextArea(20, 40);
        private JButton openButton  = new JButton("Open"),
                        saveButton  = new JButton("Save");    private JFileChooser chooser= new JFileChooser();
        final private String newline = "\n";
    }
      

  6.   

    你用这个代码试一下,你最好用字符的方式处理
    JTextArea jtFunction=new JTextArea();
      String sFunction=jtFunction.getText();
    PrintWriter out=new PrintWriter(new FileWriter(fDir+"\\"+sFileName));
    out.println( sFunction );
    out.close();