代码拉取完成,页面将自动刷新
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();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。