發表文章

byteBuffer

  package   com . example ; //import java.nio.ByteBuffer; //導入依賴的package包/類 import   java . io . IOException ; import   java . nio . ByteBuffer ; import   java . nio . CharBuffer ; import   java . nio . channels . SeekableByteChannel ; import   java . nio . charset . Charset ; import   java . nio . charset . StandardCharsets ; import   java . nio . file . Files ; import   java . nio . file . Path ; import   java . nio . file . Paths ; /**  * Hello world!  *  */ public   class   App   {      public   static   void   main (  String []  args  )     {          System . out . println (  "Hello World!"  );          //String file="C:\\Work\\Java\\data\\19027835361399637";          Path   file  =  Paths . get ( "C: \\ Work \\ Java \\ data \\ 19027835361399637" );          //Path file = Paths.get(System.getProperty("user.home") + "/test/myfile.txt");          try  ( SeekableByteChannel   sbc  =  Files . newByteChannel ( file )) {  // |\longremar

byte <--> String

  package   com . example ; //import java.nio.ByteBuffer; //導入依賴的package包/類 import   java . io . IOException ; import   java . nio . ByteBuffer ; import   java . nio . CharBuffer ; import   java . nio . channels . SeekableByteChannel ; import   java . nio . charset . Charset ; import   java . nio . charset . StandardCharsets ; import   java . nio . file . Files ; import   java . nio . file . Path ; import   java . nio . file . Paths ; import   java . util . Arrays ; import   java . io . RandomAccessFile ; /**  * Hello world!  *  */ public   class   byteRead   {      public   static   void   main (  String []  args  )  throws   IOException     {          System . out . println (  "Hello World!"  );          String   fileName = "C: \\ Work \\ Java \\ data \\ 19027835361399637" ;                   RandomAccessFile   f  =  new   RandomAccessFile ( fileName ,  "r" );          byte []  b  =  new   byte [( int ) f . length ()];          f . readFully ( b );