读取“二进制” JS 中文件中的字符?
现在,当我说二进制时,我的意思是 ghjkl54╞←‼╝454
┴ 而不是 10101110
。
我想用 JavaScript 加载瓦片地图,但我不想重写用 Java 编写的地图编辑器,它将地图导出为二进制文件。所以我想知道,如果可能的话,我该怎么做?
另外,如果不可能,我是否应该读取只有 [width][height][tilenum],[[tilenum2],tilenum3],...] 的tilemap结构?
Now when I say binary, I mean ghjkl54╞←‼╝454
┴ and not 10101110
.
I wanna load a tilemap in JavaScript, but I don't want to rewrite my map editor, written in Java, which exports maps as binary files. So I was wondering, if it's possible, how would I do this?
Also, if it isn't possible, should I read a tilemap structure where I only have [width][height][tilenum],[[tilenum2], tilenum3],...]
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,使用 HTML5 文件 API,您可以读取文件的内容。请注意,并非所有浏览器都支持此功能。
通过使用
FileReader
并使用readAsBinaryString
,您可以获得这些字符: http://jsfiddle.net/S4mEv/3/。Yes, using the HTML5 File API you can read a file's contents. Note that this is not yet supported in all browsers.
By using a
FileReader
and usingreadAsBinaryString
, you can get those characters: http://jsfiddle.net/S4mEv/3/.这个问题对我来说不是很清楚,您是否需要帮助来实际将文件转换为 javascript 二进制字符串或读取已经采用 javascript 二进制字符串格式的文件?如果是后者,也许我的回答会有所帮助。
我在 javascript 中创建并使用了一个类来执行这些操作,其工作原理如下:
该类:
已使用 .wav 文件进行了大量测试。
The problem is not very clear to me, do you need help with actually getting a file into javascript binary string or reading a file that is already in javascript binary string format? If latter, maybe my answer could help.
I have made and used a class in javascript for these operations that works like this:
The class:
Has been tested with .wav files a lot.