Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

java - how to use "tab space" while writing in text file

 SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy_HHmmSS");
 String strCurrDate = formatter.format(new java.util.Date());
 String strfileNm = "Cust_Advice_" + strCurrDate + ".txt";
 String strFileGenLoc = strFileLocation + "/" + strfileNm;
 String strQuery="select name, age, data from basetable";
 try {

     stmt = conn.createStatement();
     System.out.println("Query is -> " + strQuery);
     rs = stmt.executeQuery(strQuery);

     File f = new File(strFileGenLoc);
     OutputStream os = (OutputStream)new FileOutputStream(f);
     String encoding = "UTF8";
     OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
     BufferedWriter bw = new BufferedWriter(osw);

     while (rs.next() ) {

         bw.write(rs.getString(1)==null? "":rs.getString(1));
         bw.write("  ");
         bw.write(rs.getString(2)==null? "":rs.getString(2));
         bw.write("  ");

     }
     bw.flush();
     bw.close();
 } catch (Exception e) {
     System.out.println(
         "Exception occured while getting resultset by the query");
     e.printStackTrace();
 } finally {
     try {
         if (conn != null) {
             System.out.println("Closing the connection" + conn);
             conn.close();
         }
     } catch (SQLException e) {
         System.out.println(
             "Exception occured while closing the connection");
         e.printStackTrace();
      }
    }
         return objArrayListValue;
  }

i need "one tab space" in between each column(while writing to text file). like

   manu 25 data1
   manc 35 data3

in my code i use bw.write(" ") for creating space between each column. how to use "one tab space" in that place instead of giving "space".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use to create a tab in a file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...