
+ 110010
___________
= 11000110
=十进制的198
跟十进制加法一样最低位对齐,从低位开始相加,逢2进1.
import java.io.*public class FileDemo{
public static void main(String[] args)throws Exception{
SetFile("D:\\a.txt")
}
//读取方法
private static String getFile(String pathName)throws Exception{
BufferedReader br = new BufferedReader(new FileReader(pathName))
StringBuilder sb = new StringBuilder()
String line = null
while((line=br.readLine())!=null){
for(int i = 0 i < line.length() i++){
sb.append("-")
}
sb.append(new char[]{'\r','\n'})
sb.append(line)
sb.append(new char[]{'\r','\n'})
}
br.close()
return sb.toString()
}
//写入方法
private static void SetFile(String pathName)throws Exception{
String text = getFile(pathName)
BufferedWriter bw = new BufferedWriter(new FileWriter(pathName))
bw.write(text)
bw.close()
System.out.println("写入成功!")
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)