β ꡬ쑰
μΌλ¨ macOS κΈ°μ€ brewλ‘ μ€μΉν ν°μΊ£ μλ² κ΅¬μ‘°λ μ΄λ κ² μκ²Όλ€.
/opt
βββ homebrew
βββ Cellar
βββ tomcat@9
βββ 9.0.91
βββ bin
βββ libexec
βββ webapps
βββ lms1
βββ index.jsp
βββ WEB-INF
βββ classes
βββ Student.class
βββ Department.class
βββ DepartmentManage.class
βββ lms2
βββ index.jsp
βββ students.csv
βββ WEB-INF
βββ classes
βββ Student.class
βββ Department.class
βββ DepartmentManage.class
μμ μ€μ΄λ ν΄λλ lms2μ΄κ³ ,
DepartmentManage.classμμ students.csv νμΌμ μ½μΌλ €κ³ νλλ°
κ³μ λͺ»μ½μ΄μ κ½€ μ€λ μ½μ§μ νλ€.
νμΌμ λͺ» μ½μλ μ΄μ λ
DepartmentManage.class νμΌμ΄ μ€νλ λ, νμΌμ μ½λ λν΄νΈ pathκ°
`/opt/homebrew/Cellar/tomcat@9/9.0.91/libexec/webapps/lms2` νμ μ΄λκ°μΌκ±°λΌκ³ μκ°νλλ°
(μ ννλ `lms2/` , `WEB-INF/`, `WEB-INF/classes`, `WEB-INF/classes/students` μ€μ νλμΌ κ±°λΌκ³ μμνλλ°)
μκ³ λ³΄λ `/opt/homebrew/Cellar/tomcat@9/9.0.91/bin`μ΄μλ€.
(System.getProperties("user.dir") μ μ΄μ©ν΄μ νμ¬ μμ λλ ν 리λ₯Ό μΆλ ₯ν΄λ³΄μλλ
.classνμΌμ μμΉκ° μΆλ ₯λμ§ μκ³
μ ν리μΌμ΄μ μ΄ μ€νλλ μμΉμΈ /bin ν΄λκ° μΆλ ₯λλ κ²μ νμΈνμλ€.
ν΄κ²° λ°©λ²μ λ κ°μ§μ΄λ€.
1. System.getProperties("user.dir") λ‘ μ ν리μΌμ΄μ μ€ν κ²½λ‘λ₯Ό κ°μ Έμ¨ λ€, λλ¨Έμ§ κ²½λ‘ μ‘μμ£ΌκΈ°
System.getProperty("user.dir") -> `/opt/homebrew/Cellar/tomcat@9/9.0.91/bin`
new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() -> `/opt/homebrew/Cellar/tomcat@9/9.0.91`
filePath -> `/opt/homebrew/Cellar/tomcat@9/9.0.91/libexec/webapps/lms2/students.csv`
public class DepartmentManage {
...
public void readCsv(String fileName) {
String filePath = new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() +
File.separator + "libexec" + File.separator + "webapps" + File.separator +
"lms2" + File.separator + fileName;
try(BufferedReader reader = new BufferedReader(new FileReader(filePath));) {
String line;
while((line = reader.readLine()) != null) {
...
}
} catch(IOException e) {
}
}
}
2. μ€νμν€λ .class νμΌμ΄ μλ κ²½λ‘λ₯Ό κ°μ Έμμ, csv νμΌ κ²½λ‘ μ‘μμ£ΌκΈ°
μ΄λλ νμΌμ μ°ΎκΈ° μ½λλ‘, csv νμΌμ .class νμΌκ³Ό κ°μ ν¨ν€μ§μ μμΉμμΌ°λ€.
public class DepartmentManage {
...
public void readCsv(String fileName) {
try(BufferedReader reader = new BufferedReader(
new InputStreamReader(DepartmentManage.class.getResourceAsStream(fileName), "UTF-8"));
) {
String line;
while((line = reader.readLine()) != null) {
...
}
} catch(IOException e) {
}
}
}
'μ€λ₯ ν΄κ²°' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Docker] Docker μ€μΉμ μ€ν μ€ μλ¬ (0) | 2024.08.29 |
---|---|
[Docker] tcp:lookup registry-1.docker.io on server misbehaving (0) | 2024.08.29 |
[java] ν¨ν€μ§ μΈλΆμ μλ ν΄λμ€ import μ λλ μ΄μ (0) | 2024.07.22 |
(maven) java: package org.junit.jupiter.api does not exist ν΄κ²° (0) | 2024.07.18 |
resources/data.sql μλμΌλ‘ μ€νλμ§ μλ λ¬Έμ (0) | 2024.03.08 |