397dd497df0d3ff6e9ec7a8c236dd0cdfbc6bc6b.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.sinosoft.lz.common.print;
  2. /**
  3. *
  4. * @author 徐聪渊
  5. * @E-mail 123xucongyuan@163.com;cw_xcy@hotmail.com
  6. * @version 创建时间:2009-5-22 上午11:50:18
  7. *
  8. */
  9. import java.io.BufferedReader;
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.FileNotFoundException;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16. import java.io.InputStreamReader;
  17. import java.io.OutputStream;
  18. import java.io.OutputStreamWriter;
  19. import java.io.PrintStream;
  20. import java.io.PrintWriter;
  21. import java.io.UnsupportedEncodingException;
  22. import java.util.ArrayList;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import java.util.StringTokenizer;
  26. import javax.servlet.ServletContext;
  27. import javax.servlet.http.HttpServlet;
  28. @SuppressWarnings({ "unused", "serial" })
  29. public class MakeFielsTemplate extends HttpServlet{
  30. public boolean makeFiles(String fileName, String[] str, String fileXmlNum, String path) {
  31. try {
  32. // 这个读过过程可以参阅 readToBuffer 中的注释
  33. File newfile = new File(path + "\\" + fileName + ".doc");
  34. OutputStream os = new FileOutputStream(newfile);
  35. PrintWriter writer = null;
  36. try {
  37. writer = new PrintWriter(new OutputStreamWriter(os, "utf-8"));
  38. } catch (UnsupportedEncodingException e) {
  39. e.printStackTrace();
  40. }
  41. String[] srs = FileFactory.getCaseModel().getCaseXmlList().get(fileXmlNum);
  42. String output = new String();
  43. for (int i = 0; i < srs.length - 1; i++) {
  44. output = output + srs[i] + str[i];
  45. }
  46. output = output + srs[srs.length - 1];
  47. writer.println(output);
  48. writer.flush(); // 最后确定要把输出流中的东西都写出去了
  49. os.close(); // os 关闭
  50. return true;
  51. } catch (Exception e) {
  52. return false;
  53. }
  54. }
  55. // public void makeFiles (String caseID,String fileName,String[] str,String
  56. // fileXmlNum) throws IOException {
  57. // // 这个读过过程可以参阅 readToBuffer 中的注释
  58. // long a = System.currentTimeMillis();
  59. // OutputStream os = null;
  60. // fileName=constantPath.files3+".doc";
  61. // String saveFilePath=constantPath.getRealFilesPath();
  62. // boolean flag=false;
  63. // File dir=new File(saveFilePath);
  64. // File[] files= dir.listFiles();
  65. // for(int j=0;j<files.length;j++){
  66. // if(files[j].getName().equals(caseID)){
  67. // flag=true;
  68. // break;
  69. // }
  70. // }
  71. // if(!flag){
  72. // File newfile=new File(saveFilePath+"\\"+caseID,fileName);
  73. // newfile.getParentFile().mkdir();
  74. // try {
  75. // os=new FileOutputStream(newfile);
  76. // } catch (FileNotFoundException e) {
  77. // // TODO Auto-generated catch block
  78. // e.printStackTrace();
  79. // }
  80. // }else if(flag){
  81. // File newfile=new File(saveFilePath+"\\"+caseID,fileName);
  82. // try {
  83. // os=new FileOutputStream(newfile);
  84. // } catch (FileNotFoundException e) {
  85. // // TODO Auto-generated catch block
  86. // e.printStackTrace();
  87. // }
  88. // }
  89. // PrintWriter writer = null;
  90. // try {
  91. // writer = new PrintWriter(new OutputStreamWriter(os,"utf-8"));
  92. // } catch (UnsupportedEncodingException e) {
  93. // // TODO Auto-generated catch block
  94. // e.printStackTrace();
  95. // }
  96. // String[] srs=FileFactory.getCaseModel().getCaseXmlList().get(fileXmlNum);
  97. // String output=new String();
  98. // for(int i=0;i<srs.length-1;i++){
  99. // output=output+srs[i]+str[i];
  100. // }
  101. // output=output+srs[srs.length-1];
  102. // writer.println(output);
  103. // writer.flush(); // 最后确定要把输出流中的东西都写出去了
  104. // os.close(); // os 关闭
  105. //
  106. // }
  107. }