File file = new File("d:\\tmp\\test.txt");
String arrStr[] = {
"Hello World",
"안녕하세요",
"Happy day",
"Nice Day",
};
String arrayStr[] = dataLoad(file);
for (int i = 0; i < arrayStr.length; i++) {
System.out.println(arrayStr[i]);
}
static String[] dataLoad(File f) {
String str[] = null;
try {
FileReader fr = new FileReader(f);
// 데이터를 카운터 (몇개?)
int count = 0;
String s;
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null) {
count++;
}
br.close();
// 배열을 셋팅
str = new String[count];
// 읽고 데이터를 저장
int i = 0;
fr = new FileReader(f);
br = new BufferedReader(fr);
while((s = br.readLine())!= null) {
str[i] = s;
i++;
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}