0
点赞
收藏
分享

微信扫一扫

java io换行输入文件

三千筱夜 2023-03-27 阅读 127

package com.write;


 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;

 public class LinerHuanghang {

     /**
      * @param args
      * @throws Exception
      */
     public static void main(String[] args) throws Exception {

 //        FileOutputStream fos = new FileOutputStream("testd.txt ");
 //        String nextLine = System.getProperty("line.separator");
 //        String testStr = "abcd " + nextLine + "efgh " + nextLine + "igkl ";
 //        byte[] c = testStr.getBytes();
 //        fos.write(c);
 //        fos.close();
         
         FileOutputStream fos = new FileOutputStream("e.txt ");
         
          List<String[]> lists = new ArrayList<String[]>();
          
          String[] str0 = {"1","2","3","4","5"};
          String[] str1 = {"1","2","3","4","5"}; 
          String[] str2 = {"1","2","3","4","5"}; 
          String[] str3 = {"1","2","3","4","5"};
          String[] str4 = {"1","2","3","4","5"}; 
          String[] str5 = {"1","2","3","4","5"}; 
          String[] str6 = {"1","2","3","4","5"};
         
          lists.add(str0);
          lists.add(str1); 
          lists.add(str2); 
          lists.add(str3); 
          lists.add(str4); 
          lists.add(str5); 
          lists.add(str6);
          
          String newLine = System.getProperty("line.separator");//换行标志
          
          
          for(int i=0;i<lists.size();i++){
              
              String[] str = lists.get(i);
               
              for(int j=0;j<str.length;j++){
                 byte[] c = str[j].getBytes();
                 fos.write(c);
                 if(j!=str.length-1){
                   fos.write(",".getBytes());
                 }
              }//end for(j
              if(lists.size()-1!=i){
                  
                fos.write(newLine.getBytes());
                
              }
          }//end for(i
         
           fos.close();
     }

 }

举报

相关推荐

0 条评论