본문 바로가기

카테고리 없음

FileReader로 읽은 int값 Char를 이용하세요.

반응형
 private String loopString(FileReader fileReader) throws IOException {  
  StringBuilder stringBuilder = new StringBuilder();
  int priInt = 0;
  while((priInt = fileReader.read()) != -1){
   char strFile = (char)priInt;
   stringBuilder.append(strFile);
  }
  return stringBuilder.toString();
 }
 
 * 위의 소스에서 FileReader를 가져오면 이것을 문자열로 보고 싶다면 char로 형변환 하라.
 일단 FileReader로 읽으면 숫자로 나오는데 이것이 원래 문자열이었다면 문자열의 primitive type 은 Char 이므로 Char로 형 변환 해야 한다.
 
몰라서 Hex 로도 바꾸고
String aa = Integer.toHexString(priInt);
등등의 뻘짓을 함.
반응형