写入二进制文件

public static void getBitFromString(String string) {
		try {
			FileWriter fw = new FileWriter("c:\\a.txt");
			byte[] byts = string.getBytes();
			for (int i = 0; i < byts.length; i++) {
				fw.write(byts[i]);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void getBitFromByte(byte[] byts) {
		try {
			FileWriter fw = new FileWriter("c:\\a.txt");
			String result = "";
			for (int i = 0; i < byts.length; i++) {
				result += Integer.toBinaryString(byts[i]);
			}
			fw.write(result); 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	}

你可能感兴趣的:(二进制)