0

So I've been searching for a simply way to read a file and store each string line by line as you go through the file. I know how to do it in Java where you have a file variable and just do file.nextLine() to proceed to the next line till you hit the end.

Was wondering if there is a simple way to just do that. I have a HTML file that has a button with an input tag that grabs a file, but I don't know the syntax to store the file variable in JavaScript and do a loop going line by line and storing each line in different variables.

Thanks for your time and for the help in advance.

<button id="list">List All Recipes</button>
<button id="add">Add Recipe</button>
<input id="inputFile" type="file" style="display: none;" />
    <button id="remove">Remove Recipe</button>
    <button id="update">Update Recipe</button>


<script>
    //variable declaration
    var recipeList = [];


    //jQuery for button click event
    $('#add').on('click', function() {
        $('#inputFile').trigger('click');
    });
</script>
Alex Li
  • 1
  • 1
  • 1
    Please post your code. – imtheman Jul 07 '16 at 22:59
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/FileReader – Nekomajin42 Jul 07 '16 at 23:00
  • read a file? are we talking about Node here or the browser? you are very vague about this. – vsync Jul 07 '16 at 23:09
  • my apologize, I want to read a local .txt file. So I can prompt a window to choose a file, then read from it. – Alex Li Jul 07 '16 at 23:12
  • 2
    Possible duplicate of [Read FileReader object line-by-line without loading the whole file into RAM](http://stackoverflow.com/questions/30440709/read-filereader-object-line-by-line-without-loading-the-whole-file-into-ram) – Mike Cluck Jul 07 '16 at 23:13
  • Well those all seem way to complex. Just a simple read a line in a text file, store it in a string, then read the next line. Nothing more haha. – Alex Li Jul 08 '16 at 04:33

0 Answers0