Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

An example Analysis of data Transmission between Nio channels of java8

Shulou Source: shulou.com Published: 2022-06-01 20:33:33 10月01日 Update

This article mainly introduces "java8 Nio channel data transmission example analysis", in daily operation, I believe many people in java8 Nio channel data transmission example analysis problems have doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "java8 Nio channel data transmission example analysis" doubts helpful! Next, please follow the small series to learn together!

/* * Data transfer between channels (direct buffer)* transferFrom * transferTo * */@Testpublic void test3(){ FileChannel inChannel=null; FileChannel outChannel=null; try { inChannel=FileChannel.open(Paths.get("1.jpg"), StandardOpenOption.READ); outChannel=FileChannel.open(Paths.get("4.jpg"),StandardOpenOption.READ,StandardOpenOption.WRITE,StandardOpenOption.CREATE_NEW); // inChannel.transferTo(0, inChannel.size(), outChannel); //and the above line of code reason a meaning outChannel.transferFrom(inChannel, 0, inChannel.size()); }catch (IOException e){ e.printStackTrace(); }finally {if(inChannel!= null){try { inChannel.close(); } catch (IOException e) { e.printStackTrace(); } }if(outChannel!= null){try { outChannel.close(); } catch (IOException e) { e.printStackTrace(); } } }} At this point, the study of "Data transmission example analysis between Nio channels of java8" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Between data data transfer channel transmission analysis learning more help practical next one line code meaning article method theory knowledge article buffer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB vpn MySQL Apple