【发布时间】:2016-01-06 12:02:28
【问题描述】:
我的一些打印机有问题,我的 chrome 应用程序在文件夹中创建包含内容的文件(.xml),然后打印机打印它,但问题是 chrome 首先创建空文件,然后在其中写入内容..
喜欢这个问题的答案之一:"Premature end of file" error when Java read and writes XML data files
将您的文件写入name.xml.part,然后一旦完成/关闭到一个 重命名为 thename.xml,这使得写入更接近于原子—— 只要它确实完成了,读者就无法阅读它 仅查找“.xml”文件。
如何在 chrome 应用中做到这一点?
这是我目前的代码:
chrome.fileSystem.getWritableEntry(printer_location, function(entry) {
var uniqid = (Math.floor((Math.random() * 10) + 1)+Date.now()).toString();
entry.getFile(uniqid+'.xml', {create:true}, function(entry) {
entry.createWriter(function(writer) {
writer.write(new Blob([xmlPrintText], {type: 'text/plain'}));
});
});
});
此代码创建文件,但我需要使用.part 创建,然后在完成后重命名它而不使用 .part。
【问题讨论】:
标签: xml google-chrome printing google-chrome-extension google-chrome-app