当你输入了多少出现的错误?
用String 输入是由限制的。。//我想是因为这样

解决方案 »

  1.   

    你换成StringBuffer看看。
    如果太长,你就把他分成几次输入。
    StringBuffer s=new StringBuffer();
    s.append("ssssssssssssssssssssssssss");//每次不要超出65537个字节。
    s.append("ssssssssssssssssssssssssss");
    看看还会不会有这样的错误。
    PrintWriter pw = new PrintWriter(new FileOutputStream(path));
    pw.println(str.toString);
      

  2.   

    String str = "Begin";
    for(int i = 0;i< 5000;i++){
                str += "你好,这是一个测试,如果你有什么问题,请与我联系!好不好?可不可以?";     
         }
        
         test.WriteFile("c:\\test.txt",str);实际上,我写了这么多字也没出错!
      

  3.   

    哦,我用的是 JDK 1.4.1
      

  4.   

    请问 Falcon2000(猎鹰) test是怎么定义?还有我用在linux下的。
      

  5.   

    提示是你字符集出错,
    java.lang.ArrayIndexOutOfBoundsException
    at sun.io.CharToByteGB18030.convert(CharToByteGB18030.java:183)
    at sun.io.CharToByteConverter.convertAny(CharToByteConverter.java:139)
    没做过,不知道,理解的对不对
      

  6.   

    import java.io.*;public class Test  {

        public Test() {
        }
     
        void WriteFile(String path,String str){
         try {
          PrintWriter pw = new PrintWriter(new FileOutputStream(path));       pw.println(str);
                   pw.close();
         }
         catch (IOException e) {
         System.out.println(e.getMessage());
             System.out.println("写文件出错");
         }
         }
     
        public static void main(String[] args) {
         Test test = new Test();
         String str = "Begin";
         for(int i = 0;i< 5000;i++){
         System.out.println("i=" + i);
                str += "你好,这是一个测试,如果你有什么问题,请与我联系!好不好?可不可以?";     
         } 
         test.WriteFile(System.getProperty("user.dir") + 
                            System.getProperty("file.separator") + 
                            "test.txt",str);
        }}这个是我的全部代码! 在windows 2000 上没有问题,在Linux 也出错了!
      

  7.   

    public class Test  {

        public Test() {
        }
        private final static int MAX_LENGTH = 4000;
        void WriteFile(String path,String str){
            String tmp = null;
         try {
          PrintWriter pw = new PrintWriter(new FileOutputStream(path));
                 if(str.length() < MAX_LENGTH)
                    pw.println(str);
                 else {
                  int i = 0;
                  while(true){
                    if((i+MAX_LENGTH)< str.length()){
                        tmp = str.substring(i,i+MAX_LENGTH);
                        i = i + MAX_LENGTH;
                    }
                    else {
                        tmp = str.substring(i,str.length());
                        i = str.length();
                    }
                    pw.write(tmp);
                    pw.flush();
                    if(i>=str.length())
                        break;
                  }
                 }
              pw.close();
         }
         catch (IOException e) {
         System.out.println(e.getMessage());
             System.out.println("写文件出错");
         }
         }
     
        public static void main(String[] args) {
         Test test = new Test();
         String str = "Begin";
         for(int i = 0;i< 1000;i++){
         //System.out.println("i=" + i);
                str += "你好,这是一个测试,如果你有什么问题,请与我联系!"; 
         } 
         test.WriteFile(System.getProperty("user.dir")+System.getProperty("file.separator")+"test.txt",str);
        }
     }
    这是我改进过的代码,在Linux 下运行也没有问题! 你可以试试用这种方法!
      

  8.   

    非常感谢大家,我用别的方法解决了
    public static void save(String path, String str)
        {
            try
            {
                FileOutputStream fileoutputstream = new FileOutputStream(path);
                byte abyte0[] = str.getBytes();
                fileoutputstream.write(abyte0);
                fileoutputstream.close();
            }
            catch(IOException ioexception)
            {
                System.out.println("写文件出错");
            }
        }