写作十六进制和二进制值到文件 [英] Writing Hexadecimal and Binary Values to File

查看:133
本文介绍了写作十六进制和二进制值到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能写十六进制和二进制值(而不是其字符串重新presentation)到一个文件?例如,我怎么能写的十六进制值1A(26十进制)到一个文件?

previously,我使​​用的BufferedWriter尝试。


解决方案

 (NS test.core
  (:用[clojure.java.io]))(用开[OS(输出流的/ tmp / foo的)]
  (.WRITE OS 0x1A的))

请注意,与开宏是与我打交道时,会非常方便/ O。

How can I write hexadecimal and binary values (not their string representation) to a file? For example, how can I write the hexadecimal value 1A (26 in decimal) to a file?

Previously, I've tried using a BufferedWriter.

解决方案

(ns test.core
  (:use [clojure.java.io]))

(with-open [os (output-stream "/tmp/foo")]
  (.write os 0x1A))

Note that the with-open macro is quite handy when dealing with I/O.

这篇关于写作十六进制和二进制值到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆