⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writetxt.java

📁 对2000元以上的资产管理
💻 JAVA
字号:
package com.util;

import javax.swing.JTable;
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class WriteTxt {
  public WriteTxt() {
  }

  public String writeTableOrTxt(String url, JTable jTable1) {
    String path = "";
    File file = new File(url + ".txt");
    FileWriter fw = null;
    BufferedWriter bw = null;
    try {
      fw = new FileWriter(file);
      bw = new BufferedWriter(fw);
      String biaoTu =
          " 资产编号|   资产名称    |  大类名称  |  小类名称  |   价格   |  购入日期  | 状态 |  购入人  | 使用状态| 备注   ";
      bw.write(biaoTu);
      bw.newLine();
      String n = "-----------------------------------------------------------------------------------------------------------";
      for (int i = 0; i < jTable1.getRowCount(); i++) {
        String s = "";
        if (jTable1.getValueAt(i, 0) == null) {
          break;
        }
        for (int j = 0; j < jTable1.getColumnCount(); j++) {
          if (jTable1.getValueAt(i, j) != null) {
            if (j==4) {
               s+= "¥"+jTable1.getValueAt(i, j)+"     ";
            }else if(j==5){
              s+= jTable1.getValueAt(i, j).toString().subSequence(0,11);
            }
            else {
               s+= jTable1.getValueAt(i, j)+"     ";
            }
          }else{
            s+="           ";
          }
        }
        bw.write(s);
        bw.newLine();
        bw.write(n);
        bw.newLine();
        path = file.getAbsolutePath();
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    finally {
      try {
        bw.close();
        fw.close();
      }
      catch (IOException ex1) {
        ex1.printStackTrace();
      }
    }
    return path;
  }
  public boolean intxt(){
    boolean rest =false;
    return rest;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -