Java Saving Data In File Internal

In summary, the code is trying to create a new file but getting an error. It is confusing because it is not clear how to make a new file if no file is created or if a file is created then how to edit it.
  • #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??
 
Technology news on Phys.org
  • #2
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
Here's a simple Processing java example:

Java:
void setup() {
  File curdir = new File(".");
  println("curdir="+curdir.getAbsoluteFile());
}
 
  • #4
  • #5
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
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
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/
 

1. What is "Java Saving Data In File Internal"?

Java Saving Data In File Internal is a process used to store data within a file on a computer's internal storage. This is commonly used in Java programming to save data for future use or to transfer data between different systems.

2. How is data saved internally in Java?

In Java, data is saved internally by using file input/output (I/O) operations. These operations involve opening a file, writing or reading data to/from the file, and then closing the file. This can be done using various classes and methods provided by the Java API, such as the FileOutputStream and FileInputStream classes.

3. What types of data can be saved internally in Java?

Java allows for the saving of various types of data internally, including strings, integers, floats, and objects. The data is typically converted into a byte stream before being written to a file and can then be converted back to its original type when read from the file.

4. Can data be updated or deleted from a file using Java?

Yes, data can be updated or deleted from a file using Java. This can be done by opening the file in read/write mode and using the appropriate methods to make changes to the data. It is important to note that when updating data, the new data must have the same length as the original data to avoid corrupting the file.

5. Are there any security concerns when saving data internally in Java?

Yes, there can be security concerns when saving data internally in Java, especially if the data is sensitive or confidential. It is important to properly handle and protect the data by using encryption techniques or restricting access to the file. It is also recommended to regularly check and update security measures to prevent any potential breaches.

Similar threads

  • Programming and Computer Science
Replies
3
Views
346
  • Programming and Computer Science
Replies
2
Views
592
  • Programming and Computer Science
Replies
1
Views
489
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
22
Views
902
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
11
Views
984
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
12
Views
9K
Back
Top