什么是System.property意味着什么?

时间:2010-10-24 09:19:46

标签: java

我想问一下这个源代码中System.property的用途是什么?我找不到确切的答案。

public abstract class BaseIndexingTestCase extends TestCase {
protected String[] keywords = {"1", "2"};
protected String[] unindexed = {"Netherlands", "Italy"};
protected String[] unstored = {"Amsterdam has lots of bridges",
"Venice has lots of canals"};
protected String[] text = {"Amsterdam", "Venice"};
protected Directory dir;
protected void setUp() throws IOException {
String indexDir =
System.getProperty("java.io.tmpdir", "tmp") +
System.getProperty("file.separator") + "index-dir";
dir = FSDirectory.getDirectory(indexDir, true);
addDocuments(dir);
}
protected void addDocuments(Directory dir)
throws IOException {
IndexWriter writer = new IndexWriter(dir, getAnalyzer(),
true);
writer.setUseCompoundFile(isCompound());
for (int i = 0; i < keywords.length; i++) {
Document doc = new Document();
doc.add(Field.Keyword("id", keywords[i]));
doc.add(Field.UnIndexed("country", unindexed[i]));
doc.add(Field.UnStored("contents", unstored[i]));
doc.add(Field.Text("city", text[i]));
writer.addDocument(doc);
}
writer.optimize();
writer.close();
}
protected Analyzer getAnalyzer() {
return new SimpleAnalyzer();
}
protected boolean isCompound() {
return true;
}
}

这是让我感到困惑的一句话。

System.getProperty("java.io.tmpdir", "tmp") +
System.getProperty("file.separator") + "index-dir";

2 个答案:

答案 0 :(得分:2)

System.getProperty(..)调用是为了获取操作系统的temp目录:

  • java.io.tmpdir是临时目录
  • file.separator是特定于操作系统的文件分隔符 - /\

答案 1 :(得分:1)

我想这个

String indexDir =
System.getProperty("java.io.tmpdir", "tmp") +
System.getProperty("file.separator") + "index-dir";
如果找不到临时目录的属性,则

创建文件夹systemtempdir / index-dir或tmp / index-dir。