У меня есть файл, который я хочу прочитать первым 500 символов из файла в phonegap. Я читаю весь файл, как будто Но мне нужно читать только первые 500 символов.
function readRtfFile2(){
try {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
fileSystem.root.getDirectory("casepad_files", { create: true, exclusive: false }, function(directoryEntry) {
console.log("log folder is created");
directoryEntry.getFile("backup.json", { create: true, exclusive: false }, function(fileEntry) {
fileEntry.file(function(file){
var reader = new FileReader();
reader.onloadend = function(evt){
//alert(evt.target.result);
//$('#realTimeContents').val(evt.target.result);
myScroll.refresh();
//setInterval(function(){
//nativePluginResultHandler(evt.target.result);},3000);
// $("#RLTRightDiv").html(evt.target.result);
$("#scroller").html(evt.target.result);
myScroll.refresh();
var scrollerDivHeight= $('#scroller').height();
var wrapperDivHeight= $('#wrapper').height();
//alert(scrollerDivHeight);
// alert(wrapperDivHeight);
if(scrollerDivHeight<=1130){
myScroll.disable()
}
};
reader.readAsText(file);
},fail);
}, fail);
}, fail);
},
fail);
}
catch(e) {
fail(e+"fail");
}
}
Чтобы получить первые n символов строки, вы должны использовать substr(0, n)
где n - количество символов, которое вы хотите. Поэтому в вашем случае вы будете использовать:
$("#scroller").html(evt.target.result.substr(0,500));