import { Component , OnInit } from "@angular/core" ; import { knownFolders , path , File , Folder } from "@nativescript/core" ; @ Component ( { moduleId : module . id , templateUrl : "./paths.component.html" } ) export class PathsExampleComponent implements OnInit { public documents : string ; public currentApp : string ; public temp : string ; public textContentToBeSaved : string = "" ; public isContentSaved : boolean = false ; public savedContent : string ; ngOnInit ( ) { let documentsFolder = knownFolders . documents ( ) ; let currentAppFolder = knownFolders . currentApp ( ) ; let tempFolder = knownFolders . temp ( ) ; let testPath = "///test.txt" ; this . documents = path . normalize ( documentsFolder . path + testPath ) ; this . currentApp = path . normalize ( currentAppFolder . path + testPath ) ; this . temp = path . normalize ( tempFolder . path + testPath ) ; documentsFolder = knownFolders . documents ( ) ; let filePath = path . join ( documentsFolder . path , "myFiles" , "test.txt" ) ; console . log ( filePath ) ; let separator = path . separator ; console . log ( separator ) ; let folderPath = path . join ( knownFolders . documents ( ) . path , "music" ) ; let folder = Folder . fromPath ( folderPath ) ; console . log ( folder ) ; } public onSaveContentToFile ( ) { let documentsFolder = knownFolders . documents ( ) ; let myPath = path . join ( documentsFolder . path , "FileFromPath.txt" ) ; let file = File . fromPath ( myPath ) ; file . writeText ( this . textContentToBeSaved ) . then ( result => { file . readText ( ) . then ( res => { this . isContentSaved = true ; this . savedContent = res ; console . log ( "File content: " + res ) ; } ) ; } ) . catch ( err => { console . log ( err . stack ) ; } ) ; } }