0

Windows 8 app development requires a file access and i'm using html with javascript. I read the msdn articles and other questions posted here. But every answer points to accessing file read via user input in html file. But I want to access the file contents like using java FileIO. My operation would be requiring reading first line from a file into a variable...Kindly help me on this.

user1981245
  • 121
  • 1
  • 1
  • 6

1 Answers1

0

I'd assume the link posted in similar question (here https://stackoverflow.com/a/13131746/173100) helps. Just note that you can't read an arbitrary file from the file system, the allowed locations include the app's install location, app's local data folder and a bunch of predefined folders described in the linked MSDN article (http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx). Most likely you're interested in http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.getfilefromapplicationuriasync.aspx .

In practice, you could read the first line of the file foo.txt located in your app's install directory (= in your app's package) as follows:

Windows.Storage.StorageFile.getFileFromApplicationUriAsync("ms-appx:///foo.txt").done(
   function(file) {
       // Assuming file has content here, better error handling probably needed
       var lines = file.split("\n");
       var firstLine = lines[0];

       // Do something with the firstLine variable
   },
   function(error) {
       // Error occurred, handle it here
   }
);
Community
  • 1
  • 1
harriha
  • 301
  • 2
  • 5