java - System.property 是什么意思?

标签 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";

最佳答案

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

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

关于java - System.property 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4007678/

相关文章:

java - 使用 maven,如何将 war 配置到 ear 文件中

java - Proguard:保留特定方法的注释

java - 我的 STS 无法运行

Java 方法作用域找不到符号?

java - Java 是否在运行时优化了字符串的创建?

java - 合并许多 application.properties 文件而不是在 Spring Boot 上替换?

java - 如何在鼠标事件发生后从数组列表中删除对象?

java - Spark SQL 在 Spark Streaming (KafkaStream) 中失败

java - 如何设置单元格之间的空间以使单元格的内容不被删除

java - 检查java中的单词变体(词干)