Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading/Writing to a file  RSS feed

 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to be able to select a text file (I'm using <input type="file"> then read the file (not sure how this is done...) and finally add some text to the end of the file (again, not sure how this is done)...
Does anyone know of a tutorial- or is this done easily enough that you can explain it to me here?
The file will be local- so there's no uploading... I've read through some stuff on uploading, but they stopped as soon as the file was uploaded- so I never learned how to read/write to it.
Thank you,
-GL
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you going to use JSP to read/write local file?
If so, that means your server is on the same machine where your file is, so you don't really need to upload it through HTTP.
All that you really need is file name and path. So it make sense to have a <input type=file on a page to get file name, but really submit to server another form, where hidden field will have file name.
 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right... I've got that part... Now- How do I read the file? How do I append to it (tag something on the end of the file (like the date that it was read)?
Thanks,
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
 
Ruilin Yang
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can append the date of reading the file by calling the system date and write to you file stream.
 
Shubhrajit Chatterjee
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot edit a file in the client machine using HTML/javascript/ java applets .. etc... it is against security.
If you really need to do it .. ( using an applet ) then you need to write a custom security manager
 
sridhar satuloori
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think you can add some thing to the file contents while its being uploaded from the client. Other esiest way is you can add the data to the end of the file at the server end.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!