打印txt文件信息

来源:互联网 发布:mysql分类后显示合计 编辑:程序博客网 时间:2024/05/29 13:02
package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class PrintWelcome {
    

  private static void printWelcome(String welcomeFileName)
  {
    String FS = System.getProperty("file.separator");
    String welcomeFile = welcomeFileName;
    File file = new File(welcomeFile);
    try
    {
      FileReader fileReader = new FileReader(file);
      BufferedReader br = new BufferedReader(fileReader);
      StringBuffer sb = new StringBuffer(100);

      boolean firstLine = true;
      String str;
      while ((str = br.readLine()) != null)
      {
        //String str;
        if (firstLine)
        {
          sb.append(str);
          firstLine = false;
        }
        else
        {
          sb.append("\n").append(str);
        }
      }
      System.out.println(sb.toString());
      br.close();
      fileReader.close();
    }
    catch (Exception e)
    {
      System.out.println("Read welcome file error:" + e.getMessage());
    }
  }
 
  public static void main(String[] args) throws Exception
  {
      String welcomeFile = "D:\\tomcat_portal\\bin\\portalMS\\conf\\welcome.txt";
      printWelcome( welcomeFile);
  }

}




====================================
||   S S S S   DDDD     PPPPP     ||
||   S         D   D    P    P    ||
||   S         D    D   P     P   ||
||   S S S S   D    D   P    P    ||
||         S   D    D   PPPPP     ||
||         S   D   D    P         ||
||   S S S S   DDDD     P         ||
====================================



0 0
原创粉丝点击