Files are so confusing cannot create file


#1
const documents = fileSystemModule.knownFolders.documents();
      const folder = documents.getFolder("testFolder");
      const file = folder.getFile(`${"testFile"}`.txt);

      file.writeText("some random content")
        .then((result) => {
          file.readText()
            .then((res) => {
              console.log("saved sucess")
            });
        }).catch((err) => {
          console.log(err);
        });

if i run this code ill get

Error: java.lang.NullPointerException: name == null

their documentation on create file is tuff for beginners. i just want to create a file in documents folder in my mobile. how to do that???


#2

Your syntax for string template doesn’t seem valid.

Here is a random guide from internet which might help.


#3

i got how to create file but when i run this on my mobile.

 const documents = fileSystemModule.knownFolders.documents();
        const folder = documents.getFolder("testFolder");
  
        console.log(documents)
        console.log(folder)

i ll get this as a result

JS: {
JS:   "_path": "/data/data/org.nativescript.filesystems/files",
JS:   "_isKnown": true
JS: }
JS: {
JS:   "_path": "/data/data/org.nativescript.filesystems/files/testFolder",
JS:   "_name": "testFolder"
JS: }

unfortunately in my mobile _path will start as “/storage/emulated/0/folders/files.txt”, like this…
i just look the storage path details of documents folder and it started as above .

if i want to create folder i need to change the path as above. but how to create that.