Ai
2 Star 0 Fork 0

20175306王佳烁/java-besti-is-wjs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MyCP.java 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
20175306王佳烁 提交于 2019-04-27 14:32 +08:00 . MyCP代码
package 其它;
import java.io.*;
import java.*;
public class MyCP{
public static void main(String[] args) throws IOException {
//输入十进制文本
String filepath = "src\\a.txt";
String s =dataInputStream(filepath);
//将得到的二进制数存成文本
FileOutputStream fps = new FileOutputStream("src\\b.txt");
fps.write(s.getBytes());
fps.close();
}
public static String dataInputStream(String filepath) throws IOException {
File file = new File(filepath);
DataInputStream dps = new DataInputStream(new FileInputStream(file));
StringBuilder byData = new StringBuilder();
byte bt = 0;
for(int i=0;i<file.length();i++) {
//以二进制的无符号整数形式返回一个字符串表示形式
bt = dps.readByte();
String str = Integer.toBinaryString(bt);
if(str.length() == 1) {
str = "0"+str;
}
byData.append(str.toUpperCase());
}
return byData.toString();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/wjs123456/wjs20175306.git
git@gitee.com:wjs123456/wjs20175306.git
wjs123456
wjs20175306
java-besti-is-wjs
master

搜索帮助