How to read a .txt file that was downloaded locally?

Hi there,

I’ve downloaded a file from my webserver using the following code:

download = () : void => {
    this.platform.ready().then(() => {
      let pathToSaveTo = "";

      let filename = this.url.substring(this.url.lastIndexOf('/') + 1);

      if (this.platform.is('android')) {
          pathToSaveTo = cordova.file.dataDirectory + filename;
      }
      else if(this.platform.is('ios')) {
          pathToSaveTo = cordova.file.dataDirectory + filename;
      }

      let ft = new Transfer();

      ft.download(this.url, pathToSaveTo).then(() => {
          this.savedTo = pathToSaveTo;
      });
    })
  }

I’m having a lot of trouble finding out a way to then open the .txt file and read the text inside. I’ve looked for quite a while, and it seems like using Ionic native would be the best, but how exactly would I go about that? If someone could provide an example I would really appreciate it.

Thanks!

Nobody has any ideas? I’m really struggling with this.

Use http and give path to the file. Otherwise use require and import the path.

Thanks for the reply,

Is there any way that you could be a little more specific with the potential solution? By http do you mean Angular HTTP? And how exactly would that work?

try

this.http.get('data/country.json')
      .map(res => res.json())