日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
JavaSocket傳輸數(shù)據(jù)的文件系統(tǒng)介紹

Java Socket傳輸數(shù)據(jù)在進(jìn)行的時(shí)候有很多的事情需要我們不斷的進(jìn)行有關(guān)代碼的學(xué)習(xí)。只有不斷的學(xué)習(xí)才能掌握相關(guān)的問(wèn)題。下面我們就詳細(xì)的看看如何才能更好的使用這些技術(shù)。

成都創(chuàng)新互聯(lián)公司是專業(yè)的于洪網(wǎng)站建設(shè)公司,于洪接單;提供成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行于洪網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

我們將這個(gè)對(duì)象串行化至文件系統(tǒng),然后將之還原,Java Socket傳輸數(shù)據(jù)在這個(gè)過(guò)程其實(shí)類似于一個(gè)“壓扁”和“充氣”的過(guò)程,請(qǐng)注意,我們的Person類中包含一個(gè)嵌入對(duì)象,并且birthday變化,將之設(shè)置為transient限定符,這表示我們放棄了birthday的串行化;

Java代碼

 
 
 
  1. package stream.demo;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream; 
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.ObjectInputStream;
  10. import java.io.ObjectOutputStream;
  11. import java.io.OutputStream;
  12. import java.util.Date;
  13. public class Persistence {
  14. public static void main(String[] args) {
  15. Persistence.savePerson();
  16. Persistence.getPerson();
  17. }
  18. public static void getPerson() {
  19. try {
  20. InputStream in = new FileInputStream("c:\\person.dat");
  21. ObjectInputStream dataInput = new ObjectInputStream(in);
  22. Person p = (Person) dataInput.readObject();
  23. System.out.println(p.getName());
  24. System.out.println(p.getTall());
  25. System.out.println(p.getBirthday());
  26. System.out.println(p.getAddress().getCity());
  27. System.out.println(p.getAddress().getStreet());
  28. } catch (Exception e) {
  29. // TODO Auto-generated catch block
  30. e.printStackTrace();
  31. }
  32. }
  33. public static void savePerson() {
  34. Person p = new Person();
  35. p.setName("corey");
  36. p.setTall(171);
  37. p.setBirthday(new Date());
  38. p.setAddress(new Address("yiyang", "ziyang"));
  39. OutputStream out = new ByteArrayOutputStream();
  40. try {
  41. OutputStream fileOut = new FileOutputStream(new File(
  42. "c:\\person.dat"));
  43. ObjectOutputStream dataOut = new ObjectOutputStream(fileOut);
  44. dataOut.writeObject(p);
  45. dataOut.close();
  46. fileOut.close();
  47. } catch (IOException e) {
  48. // TODO Auto-generated catch block
  49. e.printStackTrace();
  50. }
  51. }
  52. }
  53. package stream.demo;
  54. import java.io.ByteArrayInputStream;
  55. import java.io.ByteArrayOutputStream;
  56. import java.io.File;
  57. import java.io.FileInputStream;
  58. import java.io.FileOutputStream;
  59. import java.io.IOException;
  60. import java.io.InputStream;
  61. import java.io.ObjectInputStream;
  62. import java.io.ObjectOutputStream;
  63. import java.io.OutputStream;
  64. import java.util.Date;
  65. public class Persistence {
  66. public static void main(String[] args) {
  67. Persistence.savePerson();
  68. Persistence.getPerson();
  69. }
  70. public static void getPerson() {
  71. try {
  72. InputStream in = new FileInputStream("c:\\person.dat");
  73. ObjectInputStream dataInput = new ObjectInputStream(in);
  74. Person p = (Person) dataInput.readObject();
  75. System.out.println(p.getName());
  76. System.out.println(p.getTall());
  77. System.out.println(p.getBirthday());
  78. System.out.println(p.getAddress().getCity());
  79. System.out.println(p.getAddress().getStreet());
  80. } catch (Exception e) {
  81. // TODO Auto-generated catch block
  82. e.printStackTrace();
  83. }
  84. }
  85. public static void savePerson() {
  86. Person p = new Person();
  87. p.setName("corey");
  88. p.setTall(171);
  89. p.setBirthday(new Date());
  90. p.setAddress(new Address("yiyang", "ziyang"));
  91. OutputStream out = new ByteArrayOutputStream();
  92. try {
  93. OutputStream fileOut = new FileOutputStream(new File(
  94. "c:\\person.dat"));
  95. ObjectOutputStream dataOut = new ObjectOutputStream(fileOut);
  96. dataOut.writeObject(p);
  97. dataOut.close();
  98. fileOut.close();
  99. } catch (IOException e) {
  100. // TODO Auto-generated catch block
  101. e.printStackTrace();
  102. }
  103. }
  104. }

以上就是對(duì)Java Socket傳輸數(shù)據(jù)的詳細(xì)介紹,希望大家有所收獲。


新聞標(biāo)題:JavaSocket傳輸數(shù)據(jù)的文件系統(tǒng)介紹
轉(zhuǎn)載來(lái)源:http://m.5511xx.com/article/dpjeppo.html