I made a post a while back but the question went unanswered. The problem I am having still persists and I am not sure how to solve it. The problem is that I am trying to write a file to my app specific directory but when I write the file it does not save to the app directory. I also tried the snippet of code on Link but I keep getting a Unresolved reference: context.
Here is my code:
val file = "code.py"
val fileOutputStream: FileOutputStream
//Creating LinkedList object
val list: MutableCollection<String> = LinkedList()
//Adding the Opcodes to the linkedlist
list.add("SS;")
list.add("BN(=X=5);")
list.add("BN(=Y=7);")
list.add("CS0507(=Y);")
list.add("BG(=7=5)Y;")
list.add("BL(=A=360);")
list.add("BL(=B=360);")
list.add("CQ(=5000);")
list.add("CG(=A);")
list.add("CG(=B);")
list.add("XX;")
try
{
//Creating the python file
fileOutputStream = openFileOutput(file, Context.MODE_PRIVATE)
//Incrementing through the list and writing to the file
for(item in list)
{
//Creating LookUp object
val opcode = LookUp()
var code: String = ""
//Function call to match Opcodes from linkedlist
code = opcode.match(item)
//Writing python code to file
fileOutputStream.write(code.toByteArray())
}
}
//Catching any file errors that could occur
catch(e: FileNotFoundException)
{
e.printStackTrace()
}
catch(e:NumberFormatException)
{
e.printStackTrace()
}
catch(e: IOException)
{
e.printStackTrace()
}
catch(e:Exception)
{
e.printStackTrace()
}
//Creating display message when generating the code
Toast.makeText(this, "Generating", Toast.LENGTH_SHORT).show()
I also tried the method given on the android documentation but I keep getting errors such as Unresolved reference: context, Unresolved reference: write
val fileName = "code.py"
val file = File(context.filesDir, fileName)
val fileOutputStream: FileOutputStream
//Creating LinkedList object
val list: MutableCollection<String> = LinkedList()
//Adding the Opcodes to the linkedlist
list.add("SS;")
list.add("BN(=X=5);")
list.add("BN(=Y=7);")
list.add("CS0507(=Y);")
list.add("BG(=7=5)Y;")
list.add("BL(=A=360);")
list.add("BL(=B=360);")
list.add("CQ(=5000);")
list.add("CG(=A);")
list.add("CG(=B);")
list.add("XX;")
try
{
//Creating the python file
context.openFileOutput(fileName, Context.MODE_PRIVATE).use{
for(item in list)
{
//Creating LookUp object
val opcode = LookUp()
var code: String = ""
//Function call to match Opcodes from linkedlist
code = opcode.match(item)
//Writing python code to file
it.write(code.toByteArray())
}
}
//Incrementing through the list and writing to the file
}
//Catching any file errors that could occur
catch(e: FileNotFoundException)
{
e.printStackTrace()
}
catch(e:NumberFormatException)
{
e.printStackTrace()
}
catch(e: IOException)
{
e.printStackTrace()
}
catch(e:Exception)
{
e.printStackTrace()
}
//Creating display message when generating the code
Toast.makeText(this, "Generating", Toast.LENGTH_SHORT).show()
Any assistance is appreciated