Java Saving Data In File Internal

  • Java
  • Thread starter fireflies
  • Start date
  • #1
fireflies
210
12
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??
 

Answers and Replies

  • #2
14,051
8,015
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.
 
  • #3
14,051
8,015
Here's a simple Processing java example:

Java:
void setup() {
  File curdir = new File(".");
  println("curdir="+curdir.getAbsoluteFile());
}
 
  • #4
fireflies
210
12
  • #5
14,051
8,015
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.
 
  • #6
fireflies
210
12
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.
 
  • #8
fireflies
210
12
Cannot it be made to internal storage?
 
  • #10
fireflies
210
12
Can you give me any link about how to encrypt or zip the files from the code?
 
  • #11
14,051
8,015
Here’s one

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

Suggested for: Java Saving Data In File Internal

  • Last Post
Replies
34
Views
2K
  • Last Post
Replies
1
Views
477
Replies
5
Views
587
Replies
2
Views
384
Replies
8
Views
718
  • Last Post
Replies
3
Views
519
Replies
6
Views
372
Replies
1
Views
464
  • Last Post
Replies
9
Views
704
Top