0

I have a Java tool, which schedules a task every 24 hours and writes the result in a result.json file. Now I want to display this result.json file on a simple website, but I know that it's not natively possible with JavaScript to access local files. But what other, simple ways exist for this problem? I try to avoid a webservice to keep the scheduling-program and the website on the same server.

Thanks!

  • 1
    When loading the page, grab the result.json file via an JavaScript XHR request and display the response text on the page. – CodeF0x Nov 15 '18 at 09:06

1 Answers1

1

You can use the object FileReader for read the file stream from your system and gets the JSON file in a string, later use JSON.parse() to get the JSON in JS object and iterate over it for pretty representing in document DOM, or you can print the string in the HTML without parse to JS object.

Here there are a very completely example of FileReader.

crespo5
  • 81
  • 7
  • In all examples I find about the FileReader there is a input where you first have to upload a file. How can i directly program the path to a file? Can i specify a filepath myself? –  Nov 15 '18 at 09:46
  • 1
    JS can't access to file system correctly, but you can upload the file with a file type input in a form.... another way would be access with AJAX but yes... you need a microservice. – crespo5 Nov 15 '18 at 16:36
  • 1
    I decided to simply write a basic webservice in Java EE. I think this will spare me some stress. I don't want to find any tricky solution, which only works partially. But thanks for the help! –  Nov 16 '18 at 07:00