Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Javascript readfile with filename

I want read file with filename But function gives me error

    var data = "class.php"
    var reader = new FileReader();
    var result  = reader.readAsText(data);
    console.log(result);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JavaScript can read local files using the FileReader() but not automatically, meaning that the user has to pass the file (or a list of files) to the script with an html <input type="file">.

After that, JavaScript will be able to process the file (or list of files).

JavaScript cannot access the filesystem of your computer for security reasons without the user input.

So, if you want to it, you will need to create an html document having that html input and then read the file content.

Then, you can handle the file in the click event handler like so:

var fr = new FileReader();
fr.onload = function(e) {
   const text = e.target.result;
};
fr.readAsText(file);

readAsText is asynchronous, you will need to use the onload callback to see the result.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda