file read
public String[] readKR(String filename) {
final int BUFFER_SIZE = 81920;
final String code = "EUC-KR";
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get(filename)), code), BUFFER_SIZE);
} catch (Exception e) {
Log.e("readKR","Exception "+e);
}
List<String> lines = new ArrayList<>();
String line;
while (true) {
try {
if ((line = bufferedReader.readLine()) == null) break;
} catch (IOException e) {
throw new RuntimeException(e);
}
lines.add(line);
}
try {
bufferedReader.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return lines.toArray(new String[0]);
}
file write
public static void writeKR(File file, String textLine) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
OutputStreamWriter OutputStreamWriter =
new OutputStreamWriter(fileOutputStream, "EUC-KR");
BufferedWriter bufferedWriter = new BufferedWriter(OutputStreamWriter);
bufferedWriter.write(textLine);
bufferedWriter.close();
} catch (Exception e) {
Log.e("writeKR","IOException "+e);
}
}
'android source ' 카테고리의 다른 글
toolbar back button 추가 (0) | 2024.09.16 |
---|---|
menu 폭 줄이는 법 (0) | 2024.08.17 |
Wifi Monitoring (0) | 2024.07.02 |
startActivityForResult deprecated (0) | 2024.05.12 |
image 를 rounding 으로 표시 (0) | 2024.04.28 |