Java中byte输出write到文件的实现方法讲解
作者:anialy 发布时间:2023-12-25 11:11:36
简述:
观察Byte值转为字符写入文件
如果在java里用byte打印出来
只有33 到 126的输出字符比较正常
此外发现Byte值为13是空格,10是换行符
知识点:
1. String 转为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: ~
来源:https://blog.csdn.net/anialy/article/details/7961179
猜你喜欢
- 一、语音聊天说专业点就是即时语音,是一种基于网络的快速传递语音信息的技术,普遍应用于各类社交软件中,优势主要有以下几点:(1)时效性:视频直
- 延迟队列的使用场景还比较多,例如:1、超时未收到支付回调,主动查询支付状态;2、规定时间内,订单未支付,自动取消;。。。总之,但凡需要在未来
- 背景ELMAH就是一个日志的拦截和处理组件,说到.net的日志组件,大家的第一反应该是Log4Net、NLog等这些东西,关于Log4Net
- 本文实例为大家分享了unity3d实现七天签到功能的具体代码,供大家参考,具体内容如下在很多游戏中都有签到功能,(这里记录的是7天连续签到功
- 异常处理机制已经成为判断一门编程语言是否成熟的标准之一,其对代码的健壮性有很大影响。一直以来异常处理使用不是很得心应手,今天对异常进行了较为
- < drawable name="white">#FFFFFF< /drawable><
- 本文详述了android抽奖程序的实现方法,程序为一个抽奖大转盘代码,里面定义了很多图形方法和动画。实现主要功能的SlyderView.ja
- 1 前言前文已经讲述了Spring BeanFactory 与 FactoryBean 的区别详情,
- 本文实例为大家分享了Java打印指定年月日历的具体代码,供大家参考,具体内容如下日历如下:程序如下://打印指定年月的日历public cl
- MongoDB的基本使用添加依赖<dependency>
- 效果图如下:默认第一次加载选择原始队列:级联效果图:关键代码给下拉列表选中事件监听绑定Id :int pos = firsthand_dlb
- 这里介绍两种方法,一种是Spannable,一种是Html.fromHtml(通过html标签来改变),实际中看您使用哪种方便选择使用即可1
- SpringBoot web项目启动后立即关闭我们在写spring boot web项目时,有时会遇到启动后立即关闭的情况,或者是无法加载某
- 本文实例为大家分享了java使用集合实现通讯录的具体代码,供大家参考,具体内容如下代码有些繁琐,只适合初学者。项目1java通讯录方法(声明
- eclipse导入appcompat项目报错解决办法我们在eclipse导入开源项目后,经常会发现找不到类似Theme.AppCompat.
- 本文实例为大家分享了C#实现网页画图的具体代码,供大家参考,具体内容如下代码贴着保存下using System;using System.C
- 如果不考虑更深层的性能问题,我个人认为ScrollerView还是很好用的。而且单用ScrollerView就可以实现分类型的Recycle
- 原理简介 & OpenGL 的优势裸眼 3D 效果的本质是——将整个图片结构分为 3 层:上
- Person实体类package com.ljq.domain;public class Person {  
- 前言在Activity间传递的数据一般比较简单,但是有时候实际开发中也会传一些比较复杂的数据,本节一起来学习更多Activity间数据的传递