2010-10-24 6 views
0

Je voudrais demander quelle est l'utilisation de System.property dans ce code source? Je ne peux pas trouver la réponse exacte.que signifie 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; 
} 
} 

c'est la ligne qui me rend confus.

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

Répondre

1

Je pense que ce

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

crée un dossier systemtempdir/index-dir ou tmp/index-dir si aucun PropertyEntry pour un répertoire temporaire a été trouvé.

2

Les appels System.getProperty(..) sont là pour obtenir le temp dir de l'OS:

  • java.io.tmpdir est la température dir
  • file.separator est le séparateur de fichier spécifique à l'OS - soit / ou \