Java Saving Data In File Internal

Click For Summary

Discussion Overview

The discussion revolves around saving data to a file in an Android application, specifically focusing on the use of internal versus external storage. Participants explore how to manage file directories, read and write operations, and the implications of data security.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant expresses confusion about the directory structure for saving files in Android and questions how to create or edit files across different activities.
  • Another suggests using filesystem APIs to determine the working directory, indicating that testing on a device may yield quicker results than searching for answers.
  • A participant shares a Processing Java example to illustrate how to find the current directory.
  • Concerns are raised about saving files in external memory, with a participant seeking clarification on how to ensure files are saved in internal memory instead.
  • One participant mentions that writing to external memory could compromise data security, as other applications can access that data.
  • Another suggests encryption as a solution to enhance data security.
  • A question is posed about the feasibility of using internal storage while ensuring data protection.
  • It is noted that if internal storage is accessible for read/write operations, other apps can also access it, prompting a discussion on encryption as a protective measure.
  • Participants share links to resources on encrypting or zipping files for added security.

Areas of Agreement / Disagreement

Participants express varying opinions on the use of internal versus external storage, with some advocating for encryption while others discuss the implications of data accessibility. The discussion remains unresolved regarding the best practices for securely saving data.

Contextual Notes

Participants reference specific Android documentation and external resources, indicating a reliance on external knowledge that may not fully address their questions. There are also unresolved technical details regarding the implementation of file operations and the use of context in Android.

Who May Find This Useful

Developers working on Android applications, particularly those interested in data storage solutions and security practices.

fireflies
Messages
210
Reaction score
13
Hello
I am trying to read data from one activity, save it to a file... and when open another activity I will be able to read that file(by opening it).

I searched for tutorials, all they are showing on the same activity. I figured out how the code works.. but I'm not able to understand what will be the directory (parent directory while saving file). This is getting me confused that how can I make new file if no file still created, or if created then edit that file in the first activity... and how to even get the directory when I want to open it in another activity??

I learned from this page first: https://developer.android.com/training/data-storage/files.html

It is confusing because here
Java:
File file = new File(context.getFilesDir(), filename);

is getting error because of the "context". What will be the context??
 
Technology news on Phys.org
Try using the filesystem apis to help you determine the working directory. Often these are questions that to search for the answer will take longer than actually testing it on your device.
 
Here's a simple Processing java example:

Java:
void setup() {
  File curdir = new File(".");
  println("curdir="+curdir.getAbsoluteFile());
}
 
Its okay to write to external memory that's the SD card. My code was to show you where it would write your file. The DOT means the current directory and the api tells you what directory is considered the current directory.
 
Actually the app is kind of a diary. If I use external data then it is not secure anymore. Other applications can read the data too.
 
Cannot it be made to internal storage?
 
  • #10
Can you give me any link about how to encrypt or zip the files from the code?
 
  • #11
Here’s one

https://www.mkyong.com/java/how-to-compress-files-in-zip-format/
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
3
Views
3K
  • · Replies 12 ·
Replies
12
Views
11K