#How to save regular array data on disk instead of memory?

1 messages · Page 1 of 1 (latest)

unborn berry
#

Short Question Above.

Long Question:
How do I save data from arrays on a disk and access it on different java programs?

spring swiftBOT
#

<@&987246399047479336> please have a look, thanks.

spring swiftBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

fallow apex
unborn berry
fallow apex
unborn berry
#

Forgot what those specific variables as a whole are called tho

lament sorrel
#

its important to know, cause it will be entirely different depending on what it contains

fallow apex
lament sorrel
#

essentially, u need to transform ur array (with all its contents) into some form of text

#

and then read it back

#

thats not trivial

unborn berry
fallow apex
lament sorrel
#

there are generally two paths u can go:

  • do u want a file that is readable by humans? (open with text editor, read and edit ...)
  • do u want a file thats not readable by humans? (open with text editor and its just gibberish)
unborn berry
fallow apex
lament sorrel
#

the first option leads u to something like JSON, for which u need a framework like Jackson
the second option leads u to java serialization or protobuf

#

for simple cases, u can also do it manually

spring swiftBOT
#

@lament sorrel

While we appreciate all efforts to help individuals, when multiple people join a conversation it can often get confusing for those asking for help. Members may be trying to lead someone down a particular thought process to get to the answer and interrupting can break this.

As a general guideline, try to avoid interrupting ongoing help scenarios unless:
• You feel incorrect information is being given.
• The question has subjective answers.
• The original helper is no longer responding.

You can of course always add additional information after the initial problem has been solved.

lament sorrel
#

all in all, we have to see an example of what u want to save. we need to see how complex it is

unborn berry
#

It's just a basic int array man

lament sorrel
#

just ints? nothing else? no doubles? no strings?

unborn berry
#

Im a noobie in java, still dont get how to set up frameworks

fallow apex
lament sorrel
#

1D array or 2D or different?

unborn berry
#

Just array. 1D

fallow apex
lament sorrel
#

as an example

#

suppose u have an array like

fallow apex
#

Please zabu

#

It's horrible

#

We are constantly stepping on each other foot

lament sorrel
#
int[] values = { 4, 2, 321, 0, 12 };

u could save it as

4,3,321,0,12
unborn berry
fallow apex
unborn berry
fallow apex
#

Files.readString(path) this method will read a file as a string

#

If the file is like
45 654 886
You can then .split(" ") to get each value

#

Then convert them

unborn berry
unborn berry
fallow apex
fallow apex
unborn berry
fallow apex
#

Also do you know List ?

unborn berry
#

Arraylist? Familiar with the name. Arrays in Arrays, yes?

#

Still dont know how it works

fallow apex
#

Right

unborn berry
#

Unrelated topic: whats the beef between u and Zabuzard??

fallow apex
#

And for writing, you can use Files.writeString(Path.of("the path"), "foo bar")

fallow apex
fallow apex
unborn berry
#

Ahh ok

fallow apex
#

Here it will write foo bar

unborn berry
#

Whats the file name going to be??

fallow apex
unborn berry
# fallow apex the path

So from what I read above,

Files.writeString(Path.of(System/Onedrive/Documents/Ehh.txt),"golden horseshoe crab");

Will generate the file Ehh.txt with the string "golden horseshoe crab" without fail

#

In that path

#

Alright, i got one thing down

#

Bonkers! In a good way

fallow apex
unborn berry
#

anyways, time to sleep