- #1
Trying2Learn
- 377
- 57
- TL;DR Summary
- reading a file
Hello
I am aware that it is not natural for JavaScript to read a file; however I see it is being done. I am trying to read a local file of 100 numbers (separated by line breaks) into an array in JavaScript
(I am aware that there are better ways to do this, but this is going to be the way I need (it has to do with ThreeJS and all runs are local files -- please understand that.)
All the examples have such power: buttons to select file names, etc. I do not need any of that. I just need something like this (allow me to make it up using C pointers)
var vector[]
var fp = openFile("./name.txt")
for( i = 0; i < 100; i++) read(fp, "%f", (vector + i))
Then, later, I can do things with that vector
The file will have only 100 numbers in the list.
The file will always have the same name.
It will exist for reading.
I am not interested in efficiency or power, or multiple files.
I do not care about closing the file, unless it is easy.Just the above. I just need to read 100 numbers from an input file.
3.14159
2.6
100.
-10.
3.4
.
.
.
etc.
What should I put in the html file
What should I put in the associated js file
Please direct me...
I am aware that it is not natural for JavaScript to read a file; however I see it is being done. I am trying to read a local file of 100 numbers (separated by line breaks) into an array in JavaScript
(I am aware that there are better ways to do this, but this is going to be the way I need (it has to do with ThreeJS and all runs are local files -- please understand that.)
All the examples have such power: buttons to select file names, etc. I do not need any of that. I just need something like this (allow me to make it up using C pointers)
var vector[]
var fp = openFile("./name.txt")
for( i = 0; i < 100; i++) read(fp, "%f", (vector + i))
Then, later, I can do things with that vector
The file will have only 100 numbers in the list.
The file will always have the same name.
It will exist for reading.
I am not interested in efficiency or power, or multiple files.
I do not care about closing the file, unless it is easy.Just the above. I just need to read 100 numbers from an input file.
3.14159
2.6
100.
-10.
3.4
.
.
.
etc.
What should I put in the html file
What should I put in the associated js file
Please direct me...