somethingfromn   2년 전

System.out.println(counter)와 bw.write(counter) 출력 값이 달라 질문합니다.

cr00   2년 전

https://docs.oracle.com/javase/8/docs/api/java/io/BufferedWriter.html#write-int-

public void write(int c) throws IOException

Writes a single character.

Overrides:
write in class Writer

Parameters:
c - int specifying a character to be written

Throws:
IOException - If an I/O error occurs

저기 들어가는 정수가 해당 정수를 문자열로 변환해서 출력해주는 게 아니라 유니코드로써 하나의 문자를 출력해주는 거에요

Integer.toString() 등을 사용해서 문자열로 직접 변환하고 전달해주셔야 합니다

somethingfromn   2년 전

맞는 말씀이시네요..

BufferedReader 자체가 String 형식 type이고, BufferedWriter 자체도 동일한데.

해당 메소드 인자 값을 착각한 것 같습니다.

정확히 메소드를 모르고 사용해서 발생한 문제였네요. 설명 감사합니다.

somethingfromn   2년 전

그럼 하단은 왜 가능한 것인가요?

하단에 i를 살펴보면 int type의 변수인데 출력이 잘 됩니다..

무슨 차이인가요?

(설마 bw.write(String 문자열 + 변수(int))를 합치게 되면, 최종 인자값은 String 타입이기 되기 때문에 출력에 문제가 없었던 것일까요?)

cr00   2년 전

네 맞습니다!

https://docs.oracle.com/javase...

The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method.
String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.
For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.

somethingfromn   2년 전

도움 감사합니다. 

댓글을 작성하려면 로그인해야 합니다.