[Java] ๐Ÿ’พ getBytes()

shrยท2022๋…„ 6์›” 3์ผ
0

Concept

๋ชฉ๋ก ๋ณด๊ธฐ
12/13
post-thumbnail

getBytes()


String ํด๋ž˜์Šค ๋‚ด์— ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋กœ, ๋ฌธ์ž์—ด์„ ๋ฐ”์ดํŠธ ๋ฐฐ์—ด (byte [])๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค.


์‚ฌ์šฉ๋ฒ•


public class Main {
	public static void main(String[] args) {		
		/* getBytes() ์˜ˆ์ œ */
		String strTest = "ํ…Œ์ŠคํŠธ ๋ฌธ์ž์—ด";
		
		/* ๋ฌธ์ž์—ด์„ ๋ฐ”์ดํŠธ ๋ฐฐ์—ด๋กœ ๋ณ€๊ฒฝ */
		byte[] toBite = strTest.getBytes();	
		System.out.println("๋ฌธ์ž์—ด โ†’ ๋ฐ”์ดํŠธ ๋ฐฐ์—ด : "+ toBite);
		
		/* ๋ฐ”์ดํŠธ ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ */
		String toString = new String(toBite);
		System.out.println("๋ฐ”์ดํŠธ ๋ฐฐ์—ด โ†’ ๋ฌธ์ž์—ด : "+ toString);
	}
}

์ฐธ๊ณ  ์ž๋ฃŒ


์ž๋ฐ” ๋ฌธ์ž์—ด, ๋ฐ”์ดํŠธ ๋ฐฐ์—ด ๋ณ€ํ™˜ String to byte[ ] ,byte[] to String [๋ถ๋ถ™๋”ฐ๋ผํ•˜๊ธฐ]

profile
๋ชปํ•˜๋‹ค ๋ณด๋ฉด ์ž˜ํ•˜๊ฒŒ ๋˜๋Š” ๊ฑฐ์•ผ ๏ฝฅแด—๏ฝฅฬฅฬฅฬฅ

0๊ฐœ์˜ ๋Œ“๊ธ€