java鎬庝箞灏哹yte鏁扮粍鍐欏叆鏂囦欢
瑕佸皢byte鏁扮粍鍐欏叆鏂囦欢锛屽彲浠ヤ娇鐢‵ileOutputStream绫绘潵瀹炵幇銆?/p>
涓嬮潰鏄竴涓ず渚嬩唬鐮侊細
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteByteArrayToFile {
public static void main(String[] args) {
try {
byte[] byteArray = {65, 66, 67, 68, 69}; // 鐢熸垚涓€涓猙yte鏁扮粍
FileOutputStream fos = new FileOutputStream("output.txt");
fos.write(byteArray); // 灏哹yte鏁扮粍鍐欏叆鏂囦欢
fos.close();
System.out.println("Byte array has been written to file successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑棣栧厛鍒涘缓涓€涓猙yte鏁扮粍锛岀劧鍚庝娇鐢‵ileOutputStream绫诲垱寤轰竴涓緭鍑烘祦骞跺皢byte鏁扮粍鍐欏叆鍒版寚瀹氱殑鏂囦欢涓€傛渶鍚庡叧闂緭鍑烘祦銆?/p>
杩愯璇ヤ唬鐮佸悗锛屽皢浼氬湪褰撳墠鐩綍涓嬬敓鎴愪竴涓悕涓簅utput.txt鐨勬枃浠讹紝骞朵笖鏂囦欢涓殑鍐呭涓篵yte鏁扮粍涓殑鍐呭銆?/p>
相关问答