printing area's of an array on different lines depending on section
so, I've been trying to figure out how to write different parts of an array out to different lines of a txt file for a project that i've been working on. I have tried multiple methods but it usually writes all of the info to one line. I am hoping to print out the different parts of the array without going in and writing out every single variable of the array that I want to have on each line. I can provide the code if needbe to make things easier.
59 Replies
⌛
This post has been reserved for your question.
Hey @Royalrex25! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
here is my code to help with potentially figuring out my issue
119ms
What exactly is the issue there?
What exactly is written in a single line?
so, I need the names to be on one line, the passwords on the next, the item names on the line below the passwords, and the prices to be on the line below the items but everything gets printed on one line per customer. each customer is seperated properly, but I need the sections mentioned above to be printed on 4 seperate lines
do you want the output txt file?
So you want all names of all users in one line?
instead of one line for each user?
no, I want the users seperated the way they are but each section of each user to be on a seperate line
per person:
Name
Passwords
Items
Costs
but I want the users to stay seperated
So there can be multiple names for a user - what should happen in that case?
I mean with the username, Name, and Last Name on the same line
I made sure that no user would have multiple names
What is
writer.write(names.trim().replaceAll(", $", "") + "\n");
supposed to do?it's supposed to write the next section to a new line
but it didn't work
Are multiple sections written in a single line?
yep, but it's supposed to be one section per line
Can you try printing
names
via System.out.println()
?
Does that print the correct thing?well, its supposed to print to a txt file
I mean for testing
If you just print
names
, does the print the right thing in its own line?
Or does it maybe print names and also the other stuff in a single line
yes I think that makes senseit doesn't print anything out
nothing or an empty line?
heres the txt file
empty line
Can you try
for testing
Is that the input or the output?
output
oh I see
and the code you asked me to put in only prints the word but nothing else
So you are iterating over the customer info
the first entry is
Username: JennyH
yep, but it only prints out the word specified in the console
but that isn't equal to anything so you just add it to
names
then you encounter FirstName: Jenny
but it also doesn't equal anything so you add it to names
etcgotta go, bot I'll continue later
thanks for the help so far
What you can do is split each of the
String
s by :
then the first element is the entry name and the second element is the valuehow would that work in terms of printing everything out?
you can still print it out as you are currently doing it
I don't think printing is the issue
then what do you think it is?
how you are getting the variables you are printing
i coded it so that the program prints the string
maybe you want to do something alone the lines of that?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
where in the code would I place it?
where you previously had the same loops and write the output
cool, thanks for the help, ill try it out now
btw that's just an example of what it could look like
wdym "just an example"?
and the "default -> {};" line errors out
idk whether that's exactly what you want
I think you can just do
default -> "";
give me an error saying it's not a statement
ok then you can just delete that line
will it break anything if I do?
no
so, now it just prints the first entry
Here is the txt
oh these are multiple entries after each other
that's why you did that
yeah
I think that one was fine except it should have been
if (info.equals("PassRecord: ")) {
(note the additional space)
and also for the otherswait, which section of the code was this for again??
I forgot
yeah, it's like that in the code
u there?
but you forgot a space in your code
where?
like here before the
"
and also for the othersohh, now I see what you meant
IT WORKS!!!! THANK YOU!!!!!!!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
you have no idea how long it took me to get that working
Thank you so much!!!
Post Closed
This post has been closed by <@595765455436644367>.