
λ°°ν¬ μ μλ κ·Έλ₯ λ‘컬 κ²½λ‘ μ½μ΄μ csv νμΌμ μλ λ΄μ©μ κ°μ Έμ€λλ‘ νκ³ , κ²°κ³Όλ μ λμλ€.
λ°°ν¬ν λλ resourcesμ csv νμΌ λ£κ³ λ΄λΆ 리μμ€ μ½μ΄μ λ μ€ μμ건λ§.. μ½κ² λμ§ μμλ€.
κ²μν΄λ³΄λ JARλ‘ ν¨ν€μ§ν΄μ μ€νμν€λ©΄ InputStreamμ μ¨μ μ½μ΄μμΌλλ€κ³ νλ€.
JAR μμ λ€μ΄μλ 리μμ€λ₯Ό classpathλ‘ μ κ·Όν΄μ μ½μ λλ νμΌμμ€ν μ μλ νμΌμ μ½μ΄μ€λ κ²μ΄ μλλΌ JAR μμ μλ νμΌμ΄λ―λ‘ getFile()λ‘ μ½μ μ μλ€κ³ νλ€.
μμ νκΈ° μ μ½λ
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
try (Reader reader = Files.newBufferedReader(Paths.get(filePath),StandardCharsets.UTF_8);
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT)) {
for (CSVRecord record : csvParser) {
if (record.size() >= 2) {
/*log.info("λ μ½λ 0λ²μ λμλ " + record.get(0));
log.info("μ΄λ¦ "+ name.length());*/
String getRecord = record.get(0);
//log.info("μ΄λ¦ "+ getRecord.length());
if (name.equals(getRecord)) {
//log.info("μ΄λ¦κ°μ "+ name);
String[] contentArray = record.get(1).split("\\n");
//log.info("λ μ½λ 1λ²μ λμλ " + record.get(1));
aiReview = Arrays.asList(contentArray);
shoesName = name;
//log.info("μ λ°μ΄λ¦" + shoesName);
break; // μ°ΎμμΌλ©΄ λ°λ³΅ μ€λ¨
}
}
}
} catch (IOException e) {
// νμΌ μ½κΈ° μμΈ μ²λ¦¬
log.error("νμΌ μ½κΈ° μ€ μ€λ₯ λ°μ: " + e.getMessage());
throw e;
}
μμ ν ν μ½λ

InputStreamμ μ¬μ©ν΄μ csv νμΌμ μλ λ΄μ©λ€μ μ½μ΄μ¨λ€.
classpathμ μλ νμΌμ κ°μ Έμ€κΈ° μν λ©μλμΈ getResourceAsStreamμ μ¬μ©ν΄μ νμΌμ μ κ·Όνλ€.
μ°Έκ³
https://www.inflearn.com/questions/46489/file-not-found-%EC%A7%88%EB%AC%B8
'Spring > π μλ¬ κΈ°λ‘' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ

λ°°ν¬ μ μλ κ·Έλ₯ λ‘컬 κ²½λ‘ μ½μ΄μ csv νμΌμ μλ λ΄μ©μ κ°μ Έμ€λλ‘ νκ³ , κ²°κ³Όλ μ λμλ€.
λ°°ν¬ν λλ resourcesμ csv νμΌ λ£κ³ λ΄λΆ 리μμ€ μ½μ΄μ λ μ€ μμ건λ§.. μ½κ² λμ§ μμλ€.
κ²μν΄λ³΄λ JARλ‘ ν¨ν€μ§ν΄μ μ€νμν€λ©΄ InputStreamμ μ¨μ μ½μ΄μμΌλλ€κ³ νλ€.
JAR μμ λ€μ΄μλ 리μμ€λ₯Ό classpathλ‘ μ κ·Όν΄μ μ½μ λλ νμΌμμ€ν μ μλ νμΌμ μ½μ΄μ€λ κ²μ΄ μλλΌ JAR μμ μλ νμΌμ΄λ―λ‘ getFile()λ‘ μ½μ μ μλ€κ³ νλ€.
μμ νκΈ° μ μ½λ
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
try (Reader reader = Files.newBufferedReader(Paths.get(filePath),StandardCharsets.UTF_8);
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT)) {
for (CSVRecord record : csvParser) {
if (record.size() >= 2) {
/*log.info("λ μ½λ 0λ²μ λμλ " + record.get(0));
log.info("μ΄λ¦ "+ name.length());*/
String getRecord = record.get(0);
//log.info("μ΄λ¦ "+ getRecord.length());
if (name.equals(getRecord)) {
//log.info("μ΄λ¦κ°μ "+ name);
String[] contentArray = record.get(1).split("\\n");
//log.info("λ μ½λ 1λ²μ λμλ " + record.get(1));
aiReview = Arrays.asList(contentArray);
shoesName = name;
//log.info("μ λ°μ΄λ¦" + shoesName);
break; // μ°ΎμμΌλ©΄ λ°λ³΅ μ€λ¨
}
}
}
} catch (IOException e) {
// νμΌ μ½κΈ° μμΈ μ²λ¦¬
log.error("νμΌ μ½κΈ° μ€ μ€λ₯ λ°μ: " + e.getMessage());
throw e;
}
μμ ν ν μ½λ

InputStreamμ μ¬μ©ν΄μ csv νμΌμ μλ λ΄μ©λ€μ μ½μ΄μ¨λ€.
classpathμ μλ νμΌμ κ°μ Έμ€κΈ° μν λ©μλμΈ getResourceAsStreamμ μ¬μ©ν΄μ νμΌμ μ κ·Όνλ€.
μ°Έκ³
https://www.inflearn.com/questions/46489/file-not-found-%EC%A7%88%EB%AC%B8