Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, so I want to be able to read a text file called Language.txt, it is already included within my code folders. I have been trying to search for a code that is not node.js and does not include an input type file to read from the text file.

here is the javascript i got so far the input parameter is from an input type file just to test it out which works but now i don't want to use the input and just directly from Language.txt:

function readFile(input) {
    alert(input);
    let file = input.files[0];  
    let reader = new FileReader();  
    reader.readAsText();
  
    reader.onload = function() {
      console.log(reader.result);
    };
  
    reader.onerror = function() {
      console.log(reader.error);
    };  
}


What I have tried:

it only works when i use an input type file. I was just wondering how to tweak the code to just directly read from Language.txt directly
Posted
Updated 12-Jun-23 22:58pm
Comments
Richard MacCutchan 13-Jun-23 3:35am    
Since Javascript runs in the browser, it will not be able to read a file from your server. You need to explain exactly what problem you are trying to solve.

1 solution

See FileReader - Web APIs | MDN[^], particularly the paragraph which states:
Quote:
The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900