I am using Kotlin to create and write to an encrypted file stored locally within the app to temporarily store login credentials, On Logout, I want to delete this file.
To create the file I am using the EncryptedFile.Builder method as below;
val encryptedFileName = "UserAuthData_.txt"
val mainKey = MasterKey.Builder(applicationContext)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val encryptedFile = EncryptedFile.Builder(
applicationContext,
File(applicationContext.applicationInfo.dataDir, encryptedFileName),
mainKey,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
I want to delete this file but can't find any way of doing so.
Any ideas would be greatly appreciated.
Thank you!
You can simply delete the file using this -
File someFile = new File(encryptedFileName);
someFile.delete();
Related
I have added a feature to an application to allow the user to create a local backup on external storage. That part is working great, but I am having trouble restoring that back up.
Using the SAF, I have found an easy way for the user to select the file they are wanting to restore. The file they choose comes back to the app as a DocumentFile
How can I open the DocumentFile and read its contents on API 26 and up?
So far I tried 2 things and neither worked:
1)
new File(myDocumentFile.getUri().getPath())
2)
I've tried this answer but it didn't work. It is also so hacky and I don't really need access to the java.io.File I just need a way to read the contents.
How does Google want us to approach reading user's files?
Kotlin code to read lines from a text file (where 'file' is a DocumentFile)
val inputStream = contentResolver.openInputStream(file.uri)
val reader = BufferedReader(InputStreamReader(inputStream))
val lines = reader.readLines()
I use SuiteScript to execute Saved Searches and save CSV files to the File Cabinet. However, the saved files are limited to 10mb or the script fails. Is there any way to work around the 10mb limit? I'm able to upload a file through the UI over 10mb in size and the ability to do so using SuiteScript would be very useful.
Thanks for any insight.
Like #bknights answered, you can use the N/task module to have NetSuite create a CSV for you.
var searchTask = task.create({
taskType: task.TaskType.SEARCH
});
searchTask.savedSearchId = 51;
searchTask.filePath = 'ExportFolder/export.csv';;
var searchTaskId = searchTask.submit();
If for whatever reason you need more control over the output, you can create files larger than 10MB using N/file#File.appendLine() to set the contents of the file line by line.
Use a SS2.0 N/task method to schedule the script to be published to a file id or path.
So, when writing parquet files to s3, I'm able to change the directory name using the following code:
spark_NCDS_df.coalesce(1).write.parquet(s3locationC1+"parquet")
Now, when I output this, the contents within that directory are as follows:
I'd like to make two changes:
Can I update the file name for the part-0000....snappy.parquet file?
Can I output this file without the _SUCCESS, _committed and _started files?
The documentation i've found online hasn't been very helpful.
out_file_name = snappy.parquet
path = "mnt/s3locationC1/"
tmp_path = "mnt/s3locationC1/tmp_data"
df = spark_NCDS_df
def copy_file(path,tmp_path,df,out_file_name):
df.coalesce(1).write.parquet(tmp_path)
file = dbutils.fs.ls(tmp_path)[-1][0]
dbutils.fs.cp(file,path+out_file_name)
dbutils.fs.rm(tmp_path,True)
copy_file(path,tmp_path,df,out_file_name)
This function copy and paste your required output file to the destination and then delete the temp files, all the _SUCCESS, _committed and _started removed with it.
If you need anything more, please let me know.
I'm trying to open a file, however if it doesn't exist I'd like to create it.
Is there a quick and easy way to open("folder/file.txt") and if file.txt doesn't exist it'll create it, and if folder doesn't exist it'll create both folder and file.txt?
I saw a few forums mention passing variations of w, a, w+, wt ECT in the open function but I still get an error.
been trying with this
with open("~/folder/file.json", "w") as json_file:
json_data = json.load(json_file)
Have a look at os.path.expanduser(path) (docs). This will perform the necessary replacement on ~.
I have a webpart that users can upload files to a document library.
a problem appears if a user uploads a file with a name identical to a file name already exists in the library.
in this case I want the new file to be added as a new version to the existing file using the object model not the web services.
how to achieve that ?
thanks
OK here's the Answer:
//byte array holding the contents of the file
byte[] contents = File.ReadAllBytes(path);
file.CheckOut();
file.SaveBinary(contents);
file.CheckIn("New version");
the trick is in the check in/ check out
thanks