Skip to main content

[JAVA 파일 입출력] 파일 절대 경로 가져오기


Image result for java

오랜만에 자바에서 간단한 파일 입출력을 해보았는데 절대 경로를 불러오는 방법이 생각보다 직관적이지 않았다. 그래서 기억해두기 위해 자료를 남긴다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public static void main(String[] args) {
    String path = 클래스이름.class.getResource("").getPath(); // 현재 클래스의 절대 경로
    try {
        FileReader fr = new FileReader(path + "myXML.xml");      
        BufferedReader br = new BufferedReader(fr);      
        System.out.println("파일 불러오기 성공!");  }
    catch (FileNotFoundException e) {
        System.out.println("파일이 존재하지 않습니다.");      
        e.printStackTrace();
    }
}
public void FileReader(String inputFile) throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(new File(inputFile)));    
    String buffer = "";
    while((buffer = br.readLine()) != null) {
        System.out.println(buffer);    
    }
    br.close();
}
cs

Comments

Popular posts from this blog

[공유] Bat 파일 명령어 모음

도스창 : 윈도우화면>시작버튼>명령어입력 부분에서 cmd.exe를 실행  --> 까만색의 화면이 뜬다. 나는 이 화면을 편의상 도스창이라고 부르겠다.  이 도스창과 과거 DOS OS와는 상관이 없다. 단지 모양이 비슷할 뿐이다. Batch file과 Shell Script는 같은 용어이다. 단, Batch file : Microsoft에서 부르는 용어. Shell Script : Linux에서 부르는 용어. 아래의 모든 설명은 MS를 기준으로 설명한다. 배치파일은 텍스트 파일로써, Shell 프로그램에서 실행되는 명령어들과 조건문들의 내용을 담고 있다. 쉘프로그램이 배치파일을 실행시키면, 한줄 한줄씩 배치파일의 내용이 실행이된다. 배치파일의 종류는 확장자가 .bat 파일    :  cmd.exe 또는 command.com으로 실행시킬 수 있다.                           확장자가 .vbs 파일   :  cscript.exe 또는 wscript.exe로 실행시킬 수 있다.                           확장자가 .js  파일     :  cscript.exe 또는 wscript.exe로 실행시킬 수 있다.    ...

Solution: react-native-maps showsUserLocation 동작 안함 해결 방법

react-navive-maps를 이용해서 지도를 구현하고 있는데 내 위치로 가기 버튼이 보이질 않았다. First of all, a reminder: for the button to be visible, some criteria are needed (OK in the OP): showsUserLocation  must be set  true  because the default is  false showsMyLocationButton  must stay  true , as is the default The issue is in a race condition between two asynchronous events: onMapReady and onLayout (noted Ready and Layout, for short, below). The decision to draw the button or not is done at the time of the Layout, and the setting of UserLocation can't be done before the Ready of the map (a handle to it is needed). Unfortunately, usually, at launch, the Layout arrives  before  the Ready. 위 글을 참조해보면 showUserLocation과 showsMyLocationButton이 모두 true로 설정되어 있어야 하고,  문제는 onMapReady과 onLayout의 동기화 문제라고한다. 버튼을 그릴지 말지가 Layout이 다 마무리 되는 시점에 결정되고  유저의 위치는 맵이 다 준비 되어야만 작동을 하는데 일반적으로 맵이 다 준비되기 전에 Layout이 먼저 그려져 버려서 버튼이 안보이는 거라고 한다. 밑에 댓글들을 쭉...