#How to save regular array data on disk instead of memory?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
What's the difference between the short and long question 🤔
Which format do you want to save it ? What does this array hold ?
Format?
And the arrays in question hold regular variables, and String
Wdym regular variables
Int, bool, float, that kind of stuff
Forgot what those specific variables as a whole are called tho
its important to know, cause it will be entirely different depending on what it contains
Why does your array hold several types at the same time?
essentially, u need to transform ur array (with all its contents) into some form of text
and then read it back
thats not trivial
No, ofc it will be only one data type. Lets say.. Int
Raw text, json, etc ?
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)
Ill go for the readable option
If you just want to save it to raw text, take your array, convert it to string and write it
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
@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.
all in all, we have to see an example of what u want to save. we need to see how complex it is
It's just a basic int array man
just ints? nothing else? no doubles? no strings?
Im a noobie in java, still dont get how to set up frameworks
Convert it to a string with a loop, write it to a file
1D array or 2D or different?
Yeah its a little practice thing
Just array. 1D
It's 4 lines
int[] values = { 4, 2, 321, 0, 12 };
u could save it as
4,3,321,0,12
After I do turn it into a file, how do i retrieve the data?
Read the file,
If you wrote int separated by space, split it, if you wrote on each line, read the lines, then parse each Integer then put them in an array
I think i need to see code to understand the process better
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
So for example
Files.readString(System/Onedrive/Documents/RandoAhhProgram.java)
And then parse that to an array somehow
What this does is break the string* apart after every whitespace?
You probably don't want to read a java program 🤔
Yes, it will return an array of string split by spaces
Oh sorry meant to use .txt
And it's Files.readString(Path.of("the path"))
Also do you know List ?
Arraylist? Familiar with the name. Arrays in Arrays, yes?
Still dont know how it works
Right
Unrelated topic: whats the beef between u and Zabuzard??
And for writing, you can use Files.writeString(Path.of("the path"), "foo bar")
foo bar
Whats that
Nah it's just that two people activelly helping is a mess
Explained here
Ahh ok
Wait so i generate a file, with the string foo bar
Whats the file name going to be??
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
It may fail because of a bunch of reasons because of how windows or your favorite os works, but yes
will do, thanks!
anyways, time to sleep