国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

Java中byte輸出write到文件的實(shí)現(xiàn)方法講解

2024-07-14 08:43:55
字體:
供稿:網(wǎng)友

簡述:

觀察Byte值轉(zhuǎn)為字符寫入文件

如果在java里用byte打印出來

只有33 到 126的輸出字符比較正常

此外發(fā)現(xiàn)Byte值為13是空格,10是換行符

知識點(diǎn):

1. String 轉(zhuǎn)為Byte輸出("UTF-8"格式)

2. FileOutputStream 使用輸出文件流

代碼:

package testChar;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class TestChar { public static void main(String[] args){ File outputFile = new File("output.txt"); FileOutputStream outputFileStream = null; // try to open file output.txt try {  outputFileStream = new FileOutputStream(outputFile); } catch (FileNotFoundException e) {  e.printStackTrace(); } //output to output.txt  for(int i = 33;i < 127;i++){  try {  String numStr = i + ": ";  byte[] numBytes = numStr.getBytes("UTF-8");  outputFileStream.write(numBytes);  //i lies in [33, 127)  outputFileStream.write(i);  outputFileStream.write("/n".getBytes());  } catch (IOException e1) {  e1.printStackTrace();  } } //close file stream try {  outputFileStream.close(); } catch (IOException e) {  e.printStackTrace(); } }}

Byte從33 到 126 的字符輸出:

output.txt  用Notepad打開:

33:   !
34:   "
35:   #
36:   $
37:   %
38:   &
39:   '
40:   (
41:   )
42:   *
43:   +
44:   ,
45:   -
46:   .
47:   /
48:   0
49:   1
50:   2
51:   3
52:   4
53:   5
54:   6
55:   7
56:   8
57:   9
58:   :
59:   ;
60:   <
61:   =
62:   >
63:   ?
64:   @
65:   A
66:   B
67:   C
68:   D
69:   E
70:   F
71:   G
72:   H
73:   I
74:   J
75:   K
76:   L
77:   M
78:   N
79:   O
80:   P
81:   Q
82:   R
83:   S
84:   T
85:   U
86:   V
87:   W
88:   X
89:   Y
90:   Z
91:   [
92:   /
93:   ]
94:   ^
95:   _
96:   `
97:   a
98:   b
99:   c
100:   d
101:   e
102:   f
103:   g
104:   h
105:   i
106:   j
107:   k
108:   l
109:   m
110:   n
111:   o
112:   p
113:   q
114:   r
115:   s
116:   t
117:   u
118:   v
119:   w
120:   x
121:   y
122:   z
123:   {
124:   |
125:   }
126:   ~

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對VeVb武林網(wǎng)的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接


注:相關(guān)教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长白| 白银市| 广德县| 克东县| 屏南县| 普安县| 张家界市| 子长县| 泸西县| 贵州省| 博白县| 吴桥县| 西乡县| 达尔| 梁山县| 丹棱县| 霍州市| 栾川县| 贵定县| 皮山县| 杂多县| 深水埗区| 长海县| 台州市| 临邑县| 睢宁县| 巴东县| 拉萨市| 怀宁县| 顺平县| 吴旗县| 桦甸市| 秦安县| 进贤县| 阿勒泰市| 武穴市| 宝兴县| 宾阳县| 蓝山县| 绥棱县| 乌鲁木齐县|