2014-11-14 58 views
-2

获取输入我要像各种查询:
project = 'abc' and status = Closed
project = 'def' and status = Open
project = 'ghi' and status = Open
如何从一个txt文件在Java

我有一个使用SendKeys函数中硒调用这些查询之一。我必须将查询保存在.txt文件中并执行此操作。

怎么办?

回答

0

尝试使用一个txt文件,如下:

project;status 
abc;Closed 
def;Open 

阅读该文件在你的程序是这样的:

private void checkProejctStats(String filePath) throws Exception{ 
    BufferedReader br = new BufferedReader(new FileInputReader(filePath)); 
    String line = br.readLine(); //This is the headerline, we don't realy need to know whats inside there. 
    line = br.readLine();//means we are going to read the 2nd line. 
    while(line !=null){ 
    String arr[] = line.split(";") //split it in an array 
    // TODO: CHECK PROPERLY! 
    String projectName = arr[0]; 
    String projectStatus = arr[1]; 
    line = br.readLine();//get the next line 
} 
} 

请认出这是我对计算器的第一篇文章,从来没有这么做过之前编码在这个编辑器,所以可能有一些语法问题;) 只是让我知道,如果有问题。