sinat_33415638 2016-02-26 01:34 采纳率: 100%
浏览 1711

程序里面有静态变量,我想执行好几遍,每次的变量值都从外面获取,我的静态变量应该怎么改

我发下主要代码吧,涉及到静态变量的。主要是想把文件路径filename和获取的source的名字改成非静态的
public class ProcessRow {
static Properties source;
static {
try {
source = new Properties();
FileInputStream fis = new FileInputStream(new File(
inputPropertieName()));
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
source.load(isr);

    fis.close();
} catch (Exception e) {
    // throw new ExceptionInInitializerError(e);
}

}

public static String filterAlphabet(String alph) {
alph = alph.replaceAll("[^(A-Z)]", "");
return alph;
}

public String Pname() {
String hai = UseProcess.fileName;
String a = filterAlphabet(hai);
String b = hai.substring(hai.indexOf(a), hai.indexOf(a) + 6);
return b;

}

public static String inputPropertieName() {
/*
* System.out.println("请输入配置文件名称:"); Scanner a = new Scanner(System.in);
* String propertieName = a.next();
*/
// a.close();
ProcessRow a = new ProcessRow();
String propertieName = a.Pname();
return propertieName;
}

// 判断方法1,2

public boolean panduan1(XSSFRow from) {
return from.getCell(8).toString().trim()
.equals(source.getProperty("I列值1"))
&& (from.getCell(2).toString().trim().equals(source
.getProperty("C列值1")));// 1 I列值为“I列值1” 且C列值为“C列值1”
}

public boolean panduan2(XSSFRow from) {
return from.getCell(8).toString().trim()
.equals(source.getProperty("I列值2"))
&& (from.getCell(2).toString().trim().equals(source
.getProperty("C列值2")));// 2 I列值为“I列值2” 且C列值为“C列值2”
}
.........

Output类
public class Output {
static Date d = new Date();
static DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
final static String fileName = df.format(d);
static String b = null;
static String c = ProcessRow.source.getProperty("输出路径")+fileName + "_main" + ".xlsx";
public static FileOutputStream init() {
FileOutputStream s = null;
try {
s = new FileOutputStream(c);
} catch (FileNotFoundException e) {
}
return s;
}
public static XSSFWorkbook getWorkbook() throws IOException{
FileInputStream fis = new FileInputStream(c);
XSSFWorkbook wb = new XSSFWorkbook( fis );
return wb;
}

}
UseProcess类
public class UseProcess {
static String fileName=UseProcess.fileName();
static XSSFSheet readsheet;
static {
try {
readsheet = readWorkbook();
} catch (Exception e) {
// TODO: handle exception
}
}
static XSSFWorkbook sc = null;
static XSSFWorkbook sr = null;
public static String fileName() {
System.out.println("请输入文件路径(将文件拖入程序):");
Scanner a = new Scanner(System.in);
String fileName = a.next();
//a.close();
return fileName;
}
ArrayList date1 = new ArrayList();
ArrayList value1 = new ArrayList();
ArrayList date2 = new ArrayList();
ArrayList value2 = new ArrayList();

int lastnum = getNum(fileName);
int i = Integer.parseInt(ProcessRow.source.getProperty("表单数据从第几行开始")) - 1;
static int j = 1;

public static int getNum(String Filename) {
try {
InputStream myxls;
myxls = new FileInputStream(Filename);
sr = new XSSFWorkbook(myxls);
XSSFSheet sheet = sr.getSheetAt(0);// 第一个工作表
return sheet.getLastRowNum();// 获取第一个工作表的行数
} catch (IOException e) {
return 0;
}
}
主函数
public class TestMain {
public static void test() throws IOException, NumberFormatException, ParseException{
UseProcess.createWorkbook();
UseProcess n = new UseProcess();
for (int i = 1; i <= Integer.parseInt(ProcessRow.source
.getProperty("condition-process的个数")); i++) {
n.UseProcess1(String.valueOf(i));
}
n.UseProcessNull();
System.out.println("输入完毕");
}
public static void main(String[] args) throws NumberFormatException, IOException, ParseException {
TestMain.test();
}

  • 写回答

1条回答

  • sinat_31535993 2016-02-26 01:44
    关注

    改就改呗,最多就是每次调用的时候在内存中重新生成一下。

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!