Click here to Skip to main content
13,191,040 members (67,840 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Pls tell me how to read a text file in javascript and i want to split that text by delimiter space..
Posted 9-Jul-13 20:23pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

If you want to read a file stored at server side, use Ajax to read it.
xmlHttp.open("GET","file.txt",true);

If you want to read a file stored in local computer, there isn't a direct way to do this. But if your local computer is a Windows computer, you can use the FileSystemObject. Take a look at here[^].
  Permalink  
Comments
Bharath Kumar Gorle 10-Jul-13 3:07am
   
By using FileReader we can read the file..But i am not getting the exact result..could you pls help me...
thanh_bkhn 10-Jul-13 3:30am
   
So how did you code? You should use "Improve question" to post your code here and we may find something wrong
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Pretty much, you can't - javascript very deliberately does not have file manipulation functions for security reasons. Imagine if you could: a rogue website could access your HDD and read (or write) and file it wanted to...

If you have a very, very good reason for this, it may be possible under exceptional circumstances and with the clients active permission, but this is not going to occur in the vast majority of cases (and any site which asked me would get told "No" and never visited again).

Why do you want to do that?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
wots up frnds 10-Jul-13 3:22am
   
for me this is enough wishing all the best bharth
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

function readSingleFile(evt) {
    //Retrieve the first (and only!) File from the FileList object
    var f = evt.target.files[0]; 
  if(f){
    var r = new FileReader();
      r.onload = function(e) { 
	   var contents = e.target.result;
       }
    }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171016.2 | Last Updated 10 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100