자바 txt file 읽어와서 map에 저장 후 출력시 오류(인코딩) 질문드립니다..

DFG의 이미지
import java.io.*;
import java.util.Scanner;
import java.util.TreeMap;
 
public class MemoMain {
    public static void main(String[] args) {
        File file = new File("C:\\Users\\Jeon\\Desktop\\user.txt");
        TreeMap<String, User> hasu = new TreeMap<>();
        String[] splitstr = null;
        Scanner scan = new Scanner(System.in);
        String num = "";
        User usr = null;
 
        try {
            FileInputStream fis = new FileInputStream(file);
            InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
 
            String buffer = "";
            while((buffer = br.readLine()) != null) {
                splitstr = buffer.split(",");
                hasu.put(splitstr0, new User(splitstr1, splitstr2, splitstr3));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        while(true) {
            usr = new User();
            System.out.println("검색하실 사용자 번호를 입력하세요");
            num = scan.nextLine();
            System.out.println(hasu.descendingKeySet());
            System.out.println(hasu.entrySet());
 
            if (hasu.containsKey(num)) {
                usr = hasu.get(num);
                System.out.println("사용자 번호 : " + num + ", " + usr);
            } else {
                System.out.println("킷값이 존재하지 않습니다.");
            }
        }
    }
}

- 코드의 목적

User.txt(UTF-8 인코딩) 파일을 읽어와서 (구분점을 ,로)
TreeMap을 사용하여 맵에 키, 벨류들을 넣어준 이후에
킷값으로 벨류들을 확인하고 싶었습니다.

- 문제 확인과정

처음에는 User.txt파일을 ANSI 인코딩시 모든 킷값에 대한 검색을 할 수는 있으나 한글이 깨지는 문제가 있었고,
txt파일을 UTF-8로 인코딩을 바꿔 준 이후는 메모장에 저장된 첫 번째 줄만 유독 킷값 인식을 못 하는 문제가 있습니다.

- 원인 추측

저는 IntelliJ IDE를 사용하고 있지만
이클립스로 킷 값 확인시 첫 번째 줄 킷 값 앞에 이상한 한자가 같이 껴서 들어가는걸 확인했고, 아마 원인은 그석때문이 아닐까 생각됩니다.
하지만 해결 방법을 찾지 못 하겠네요…
(첨부한 캡처파일처럼 IntelliJ에서는 킷값, 벨류값이 제대로 들어가있지만 킷값을 못 찾습니다.)

File attachments: 
첨부파일 크기
Image icon 출력결과 및 메모장 캡처38.57 KB
익명 사용자의 이미지

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.