아주 간단한 Try 관련입니다
찬슬기
간단한 질문입니다.;;
try문을 빠져나온 다음 try에서 가졌던 openFile 값을 밖으로 어떻게 가져와야하나요;;
자바는 뭔가 알것도 같으면서... 참.. 사람 헷갈리게 만드네요;;
--------------------------------------------------
import java.io.*;
class open
{
public static void main(String[] args)
{
////////////////////////////// 파일명 불러오기 ///////////////////////
try{
System.out.println(Hello World!);
FileReader fr = new FileReader(set.txt);
BufferedReader br = new BufferedReader(fr);
String openFile = br.readLine();
System.out.println(openFile);
br.close();
fr.close();
}
catch(Exception ex)
{
}
////////////////////////////////////////////////////////////////////////////////////
System.out.println(openFile);
}
}
-
어른처럼
감사합니다 ^ㅡ^)
-
권애교
try{ } 이 안에서 변수가 선언되기때문에 지역변수로써 블럭을 벗어나면 사용할수없습니다.
그래서 멤버변수로 선언하시면되는데
class open
{
public static void main(String[] args)
{
////////////////////////////// 파일명 불러오기 ///////////////////////
String openFile = null;
try{
System.out.println(\Hello W