1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import java.io.*; import java.nio.*; import java.nio.channels.*;
class mefile { public static void main(String[] args) throws Exception { String s = "Hello! getJAVA..안녕!! 겟자바.."; byte[] by = s.getBytes(); ByteBuffer buf = ByteBuffer.allocate(by.length); buf.put(by); buf.clear(); FileOutputStream f_out = new FileOutputStream("a2.txt"); FileChannel out = f_out.getChannel(); out.write(buf); out.close(); FileInputStream f_in = new FileInputStream("a2.txt"); FileChannel in = f_in.getChannel(); ByteBuffer buf2 = ByteBuffer.allocate((int) in.size()); in.read(buf2); byte buffer[] = buf2.array(); String a = new String(buffer); System.out.println(a); } }
|