본문 바로가기

프로그래밍/JAVA

File.separator (이미지 화면에 뿌려줄때)

어떤 운영체제에서 실행될지 알 수 없으므로 디렉토리 경로 구분자는 다음과 같이 사용하도록 한다.

File.separator 는 윈도우에서는 \, 유닉스 계열에서는 /를 나타낸다.

// 설정파일 내용(리눅스 일때)

...

DIR_PATH=/home/user/repository

...

// 설정파일 내용(윈도우즈 일때)

...

DIR_PATH=D:\\user\\repository

...

///////////////////////////////////////////////////////////////////////

Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream("설정파일경로");
props.load(new InputStreamReader(fis));

// DIR_PATH 관련 정보
DIR_PATH = props.getProperty("DIR_PATH ","").trim(); // DIR_PATH 경로정보

} catch(Exception e) {}

///////////////////////////////////////////////////////////////////////

String filename = "tmp.txt";

String OUT_PATH = DIR_PATH + File.separator + filename;

이런식으로 하면 설정변수에서 읽어들인 스트링만 가지고 출력파일의 전체경로명을 지정할 수 있다.

다음은 관련 문서이다.

java.io
Class File

java.lang.Object
  java.io.File

Field Summary
static String pathSeparator
The system-dependent path-separator character, represented as a string for convenience.
static char pathSeparatorChar
The system-dependent path-separator character.
static String separator
The system-dependent default name-separator character, represented as a string for convenience.
static char separatorChar
The system-dependent default name-separator character.

Field Detail

separatorChar

public static final char separatorChar
The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\\'.

See Also:
System.getProperty(java.lang.String)

separator

public static final String separator
The system-dependent default name-separator character, represented as a string for convenience. This string contains a single character, namely separatorChar.


pathSeparatorChar

public static final char pathSeparatorChar
The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

See Also:
System.getProperty(java.lang.String)

pathSeparator

public static final String pathSeparator
The system-dependent path-separator character, represented as a string for convenience. This string contains a single character, namely pathSeparatorChar.

 

 

'프로그래밍 > JAVA' 카테고리의 다른 글

에러노트  (0) 2012.10.22
MySQL 원격 접속시키는 방법  (0) 2012.10.17
자바 현재시간 받아오기  (0) 2012.07.18
jstl의 마지막 번째 찾기 length, begin, end, step, varStatus  (0) 2012.07.18
SiteMesh Layout적용하기  (0) 2012.06.05