无法让File()对象在eclipse

时间:2017-06-02 21:41:50

标签: java eclipse

我正在尝试检查字符串是否是我的eclipse项目中的文件。 我有这个代码:

// Lets check if query is a file
        File cfile=new File(queryX);

但是eclipse突出显示了File对象。 我已将文件对象和我在项目中使用的其他类包括在内:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;

我需要帮助,我需要知道传递给方法的字符串是文件还是纯文本 这是方法并尝试在。

中执行此操作
private void indexSearch(String indexDir, String queryX, int repeat, int hitsPerPage, String field, boolean raw) throws Exception{
    /**** Here we process the raw fields
     * so we can loop to create query
     * int fieldCount=0;
     * String[] fieldArray=rawfield.split("<");
     * // Now we check count to know to process
     * fieldCount=fieldArray.length;
     * // Now lets check count
     * if(fieldCount>0){
     * String[] fields=fieldArray;
     * }
     * else{
     * String fields=rawfield;  
     * }
     * **/

    // Here we process the searcher data
   reader = DirectoryReader.open(FSDirectory.open(Paths.get(indexDir)));
    IndexSearcher searcher = new IndexSearcher(reader);
    Analyzer analyzer = new StandardAnalyzer();

    // Lets check if query is a file
    File cfile=new File(queryX);

    BufferedReader in = null;
    if (queries != null) {
      in = Files.newBufferedReader(Paths.get(queries), StandardCharsets.UTF_8);
    } else {
      in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
    }
    QueryParser parser = new QueryParser(field, analyzer);
    while (true) {
      if (queries == null && queryString == null) {                        // prompt the user
        System.out.println("Enter query: ");
      }

      String line = queryString != null ? queryString : in.readLine();

      if (line == null || line.length() == -1) {
        break;
      }

      line = line.trim();
      if (line.length() == 0) {
        break;
      }

      Query query = parser.parse(line);
      System.out.println("Searching for: " + query.toString(field));

      if (repeat > 0) {                           // repeat & time as benchmark
        Date start = new Date();
        for (int i = 0; i < repeat; i++) {
          searcher.search(query, 100);
        }
        Date end = new Date();
        System.out.println("Time: "+(end.getTime()-start.getTime())+"ms");
      }

      doPagingSearch(in, searcher, query, hitsPerPage, raw, queries == null && queryString == null);

      if (queryString != null) {
        break;
      }
    }
}

0 个答案:

没有答案