Javascript

<script type="text/javascript" charset="utf-8">
	//*********************************************************    
    // File Capabilities
    //*********************************************************
	function getFileWriteReady() {
		$("#getFileName").val('');
		$("#textForFile").val('');
		updateWriteFileStatus('');
	}
	
    //*********************************************************    
    // File - Write
    //*********************************************************
    function appendTxt(e) {
    	var fileName = $("#getFileName").val();
    	$("#getFileName").val(fileName + '.txt');
    }
    
    function cancelWriteToFile() {
    	$("#getFileName").val('');
    }
    
   	function updateWriteFileStatus(status) {
		$("#createFileStatus").empty();
		$("#createFileStatus").append(status).trigger("create");
	}
    
    function writeToFile() {
    	var fileName = $("#getFileName").val();
    	var fileExtRegEx = /\.txt$/;
    	
    	function gotFileWriter(writer) {
    		writer.onwriteend = function(evt) {
    			$("#textForFile").val(''); 
    			$("#getFileName").val('');
    			$("#createFileProperties").css("display", "none");
    			$("#createFileProperties").empty();
    			$("#createFileStatus").empty();
    			updateWriteFileStatus(fileName + " is saved");
    		};
			writer.write($("#textForFile").val());
    	}
    	
    	function writeTxtFail(error) {
    		if ( $("#createFileProperties").css("display") == "none" ) {
    		 	 $("#createFileProperties").css("display", "block");
    			 $("#createFileProperties").append("Error: Cannot write to file. Code: " + error.code).trigger("create");
    		}
    	}
    	
    	function gotFileEntry(fileEntry) {
    		fileEntry.createWriter(gotFileWriter, writeTxtFail);
    	}
    	    	
    	function gotDirEntry(dirEntry) {
    		dirEntry.getFile(fileName, {create: true, exclusive: false}, gotFileEntry, writeTxtFail);
    	}

		if ( fileExtRegEx.test(fileName) ) { 		
    		window.resolveLocalFileSystemURI(appFullPath, gotDirEntry, writeTxtFail);   		
    	} else {
	    	    alert("ERROR: File name must end in .txt");
	    	    if ( $("#createFileProperties").css("display") == "none" ) {
	    			$("#createFileProperties").css("display", "block");
	    			$("#createFileProperties").append("ERROR: Incorrect file name extension").trigger("create");
    		}
    	}
    }
    
    //*********************************************************    
    // File - Read
    //*********************************************************    
    function updateReadFileStatus(status) {
		$("#readFileStatus").empty();
		$("#readFileStatus").append(status).trigger("create");
	}
	
    function readFile(fileName) {
    	function readTxtFail(error) {
    		updateReadFileStatus("ERROR: Cannot read file. Code: " + error.code);
    	}
    
    	function readAsText(file) {
    		var reader = new FileReader();
    		reader.onloadend = function(evt) {
    			var fileContents = evt.target.result.replace(/\n/g, "<br/>");
    			
    			$("#readFileName").append("<span>File Name: </span>" + textFormat(fileName));       		    			
    			$("#readFileContent").append(fileContents).trigger("create");
    		};
			reader.readAsText(file);			 
    	} 	
    	
        function gotFileEntry(fileEntry) {
    		fileEntry.file(readAsText, readTxtFail);
    	}
    	
    	window.resolveLocalFileSystemURI(appFullPath + "/" + fileName, gotFileEntry, readTxtFail); 
    	$("#readFileContent").empty();
    	$("#readFileName").empty();
    }

    function listDirForRead() {
		$("#readFileName").empty();
    	$("#readFileContent").empty();
		$("#readFileContent").append("Press arrow to show file content here").trigger("create");
		    
		function fileObjSuccess(file) {
		    var fileRow  = "<li>";
		    	fileRow += "<a href='#' onclick='readFile(\"" + file.name + "\");'><h4>" + textFormat(file.name) + "</h4>";
		    	fileRow += "<p>Size: " + textFormat(file.size + " bytes") + "<br/>"; 
		    	fileRow += "Date: " + toDateStr(new Date(file.lastModifiedDate)) + "</p></a>";
		    	fileRow += "<a href='#' onclick='readFile(\"" + file.name + "\");'>Read</a>";
		    	fileRow += "</li>";

		    	$("#readFileListArea").append(fileRow);
		    	$("#readFileListArea").listview("refresh");
		}
		
		function fileObjFail(error) {
			updateReadFileStatus("ERROR: Cannot get file properties. Code: " + error.code);
		}
		  
        function listDirSuccess(entries) {     	
        	$("#readFileListArea").empty();
        	
        	var numTxtFile = 0;
        	var txtReg = /\.txt$/;         	
    		for (var i=0; i<entries.length; i++) {
    			if (txtReg.test(entries[i].name)) 
    			{
    				numTxtFile++;
    				entries[i].file(fileObjSuccess, fileObjFail);
    			}
    		}
    		if ( numTxtFile == 0 ) {
    			$("#readFileListArea").append("<li><a href='#'><h4>No .txt file found.</h4><p>Use the 'create file' button to create a new file</p></a><a href='#'>No file</a></li>");
    			$("#readFileListArea").listview("refresh");
    		}    		
    	}
    	
    	function readDirFail(error) {
    			updateReadFileStatus("ERROR: Cannot read directory");
    	}
    	
    	function listDirFail(error) {
    			updateReadFileStatus("ERROR: Cannot list directory content");	
    	}
    	
    	function readDirSuccess(entry) {
			var directoryReader = entry.createReader();
			directoryReader.readEntries(listDirSuccess, listDirFail);
		}
    	
		window.resolveLocalFileSystemURI(appFullPath, readDirSuccess, readDirFail);			
    }
    
    //*********************************************************    
    // File - Delete
    //*********************************************************    
    function updateDeleteFileStatus(status) {
		$("#deleteFileStatus").empty();
		$("#deleteFileStatus").append(status).trigger("create");
	}
	
    function deleteFile(fileName) {
    	function deleteTxtFail(error) {
    		updateDeleteFileStatus("ERROR: " + error.code);
    	}
    	
    	function deleteTxtSuccess() {
    		alert(fileName + " is removed.");
    		$("#deleteFileListArea :contains('" + fileName + "')").remove();
    		$("#deleteFileListArea").listview("refresh");
    		
    		if ( $("#deleteFileListArea > li").size() == 0 ) {
    			alert("All text files have been removed.  Returning to previous page.");
    			history.back();
    		}
    	}
    
        function deleteFileEntry(fileEntry) {
    		fileEntry.remove(deleteTxtSuccess, deleteTxtFail);
    	}

    	$("#deleteFileStatus").empty();
    	window.resolveLocalFileSystemURI(appFullPath + "/" + fileName, deleteFileEntry, deleteTxtFail);
    }
        
    function listDirForDelete() {
    	function fileObjSuccess(file) {
		    var fileRow  = "<li>";
		    	fileRow += "<a href='#'><h4>" + textFormat(file.name) + "</h4>";
		    	fileRow += "<p>Size: " + textFormat(file.size + " bytes") + "<br/>"; 
		    	fileRow += "Date: " + toDateStr(new Date(file.lastModifiedDate)) + "</p></a>";
		    	fileRow += "<a href='#' onclick='deleteFile(\"" + file.name + "\");'>Read</a>";
		    	fileRow += "</li>";

		    	$("#deleteFileListArea").append(fileRow);
		    	$("#deleteFileListArea").listview("refresh");
		}
		
		function fileObjFail(error) {
			updateReadFileStatus("ERROR: Cannot get file properties. Code: " + error.code);
		}
		  
        function listDirSuccess(entries) {     	
        	$("#deleteFileListArea").empty();
        	
        	var numTxtFile = 0;
        	var txtReg = /\.txt$/;     	
    		for (var i=0; i<entries.length; i++) {
    			if (txtReg.test(entries[i].name)) 
    			{
    				numTxtFile++;
    				entries[i].file(fileObjSuccess, fileObjFail);
    			}
    		}
    		
    		if ( numTxtFile == 0 ) {
    			$("#deleteFileListArea").append("<li><a href='#'><h4>No .txt file found.</h4><p>Use the 'create file' button to create a new file</p></a><a href='#'>No file</a></li>");
    			$("#deleteFileListArea").listview("refresh");
    		}
    	}
    	
    	function readDirFail(error) {
    		updateDeleteFileStatus("ERROR: Cannot read directory");
    	}
    	
    	function listDirFail(error) {
    		updateDeleteFileStatus("ERROR: Cannot list directory contents");
    	}
    	
    	function readDirSuccess(entry) {
			var directoryReader = entry.createReader();
			directoryReader.readEntries(listDirSuccess, listDirFail);
		}
		
		$("#deleteFileStatus").empty();
		window.resolveLocalFileSystemURI(appFullPath, readDirSuccess, readDirFail);
    }
</script>		

HTML 5/JQuery Mobile

	<!---------------------------------- Main Page --------------------------------------->
	<div data-role="page" id="main">
		<div data-role="header" data-position="fixed">
			<h1 id="appTitle"></h1>
		</div>
		<div data-role="content">	
		<ul data-role="listview" data-inset="true" data-filter="true">
			<li><a href="#fileCap" data-transition="slide">File</a></li>
		</ul>
		</div>
	</div>
	
	<!---------------------------------- File -------------------------------------------->
	<div data-role="page" data-add-back-btn="true" back-btn-text="back" id="fileCap">
		<div data-role="header">
			<h1>File functions</h1>
		</div>
		<div data-role="content">
			<ul data-role="listview" data-inset="true">
				<li><a href="#createFilePage" onclick="getFileWriteReady();">Create File</a></li>
				<li><a href="#readFilePage"   onclick="listDirForRead();"   >Read File</a></li>
				<li><a href="#deleteFilePage" onclick="listDirForDelete();" >Delete File</a></li>
			</ul>
		</div>
	</div>
	
	<!---------------------------------- File: Write ------------------------------------->
	<div data-role="page" data-add-back-btn="true" back-btn-text="back" id="createFilePage">
		<div data-role="header">
			<h1>Create File</h1>
		</div>
		<div data-role="content" data-divider-theme="e">
			<div id="createFileProperties" class="mesgBox hideIt"></div>
			<div data-role="fieldcontain" class="ui-hide-label" id="writeTextArea">
					<h5 class="hlabel">Enter text in the box below:</h5>
					<form>
						<textarea data-role="none" class="mesgBox" name="textForFile" id="textForFile" value=""></textarea>
					</form>
			</div>
			<a href="#saveToFileNamePage" data-rel="popup" data-role="button" data-inline="true" data-position-to="window">Save</a>
			
	<!---------------------------------- File: Write: Get filename ----------------------->
			<div data-role="popup" id="saveToFileNamePage" class="ui-content" data-theme="e" data-transition="pop">
				<h1>File Name</h1>
				<div data-role="fieldcontain" class="ui-hide-label">
					<form>
						<label for="getFileName">Text</label>
						<input type="text" name="getFileName" id="getFileName" value="" placeholder="File Name (must end in .txt)"></input>
					</form>
				</div>
			<a href="#" data-role="button" data-rel="back" onclick="writeToFile();">Save</a>
			<a href="#" data-role="button" data-rel="back" onclick="cancelWriteToFile();">Cancel</a>
			</div>
		<div data-role="footer">
			<div id="createFileStatus"></div>
		</div>
	</div>
	
	<!---------------------------------- File: Read -------------------------------------->	
	<div data-role="page" data-add-back-btn="true" back-btn-text="back" id="readFilePage">
		<div data-role="header">
			<h1>Read File</h1>
		</div>
		<div data-role="content" data-theme="d">
			<ul data-role="listview" data-split-icon="arrow-l" data-split-theme="c" id="readFileListArea"></ul><br/>
			<div id="readFileDisplayArea">
				<span id="readFileName">File Name:</span><br/>
				<div id="readFileContent" class="mesgBox" placeholder=""></div>
			</div>
		</div>
		<div data-role="footer">
			<div id="readFileStatus"></div>
		</div>
	</div>
		
	<!---------------------------------- File: Delete ------------------------------------>	
	<div data-role="page" data-add-back-btn="true" back-btn-text="back" id="deleteFilePage">
		<div data-role="header">
			<h1>Delete File</h1>
		</div>
		<div data-role="content" data-theme="d">
			<ul data-role="listview" data-split-icon="delete" data-split-theme="c" id="deleteFileListArea"></ul>
		</div>
		<div data-role="footer">
			<div id="deleteFileStatus"></div>
		</div>		
	</div>