ความแตกต่างระหว่างการใช้File.separatorและปกติ/ใน Java Path-String คืออะไร?
ตรงกันข้ามกับ\\ความเป็นอิสระของแพลตฟอร์มแบ็กสแลชสองครั้งดูเหมือนจะไม่ใช่เหตุผลเนื่องจากทั้งสองรุ่นทำงานภายใต้ Windows และ Unix
public class SlashTest {
@Test
public void slash() throws Exception {
File file = new File("src/trials/SlashTest.java");
assertThat(file.exists(), is(true));
}
@Test
public void separator() throws Exception {
File file = new File("src" + File.separator + "trials" + File.separator + "SlashTest.java");
assertThat(file.exists(), is(true));
}
}
การใช้ถ้อยคำคำถามถ้า/งานบน Unix และ Windows จึงควรหนึ่งเคยต้องการที่จะใช้งานFile.separator?