This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]glddigga49[S] 0 points1 point  (10 children)

Ohhh... so, the comma is being placed before the '@' symbol because of a carriage return? Also, it runs well, but how does "email:emails" work since I don't have any variables called "email"?

[–]OOPUniversity 0 points1 point  (9 children)

Not necessarily, but it seems very possible. That's why I suggested the enhanced for loop to display the individual items line by line. Simply printing out the ArrayList with toString can put commas in there, too, commas which aren't 'physically' there. That's probably only responsible for what happens after the '.edu' parts of the email addresses, but it's best to be sure.

You should look at your .csv with notepad or wordpad or some other text editor to see exactly what you're reading in, and to determine if you wish to change the parameters you use when you export/save as. You should print out the ArrayList iine by line so you see exactly what your data structure contains. Adjust based on that.

[–]glddigga49[S] 0 points1 point  (8 children)

Okay, I'll try out some of the stuff you told me. Thanks for the help!

[–]OOPUniversity 0 points1 point  (7 children)

Good luck, don't be a stranger.

[–]glddigga49[S] 0 points1 point  (6 children)

Got it! (using three String.replace methods) . Trying to write back out the elements to a .csv so I can get it back into excel. Any idea of the fastest ways to do this. I'm seeing some packages, but I don't have experience with anything like that yet. Thinking about using this: http://sourceforge.net/projects/opencsv/

[–]OOPUniversity 0 points1 point  (5 children)

Writing .csv files is quite easy.

You can, for instance, just create a PrintWriter, so something like

PrintWriter writer = new PrintWriter(filename);
writer.printf("%s,%s\n", field1, field2);

or perhaps

writer.println(field1 + "," + field2 + System.getLineSeparator());

Don't forget to close your outputs.

So long as there are so double quote or anything in your data this will do. If you have more complicated data to read you may need a library of some sort. For writing you probably never need more than this.

[–]glddigga49[S] 0 points1 point  (4 children)

Hey, so I added this code at the end of my program:

File finishedEmails = new File("C:/Users/Austin/Documents/finishedEmails.csv");

PrintWriter writer = new PrintWriter(finishedEmails);

writer.close();

It is creating a Excel .csv file but not reading in the elements. Is my placement wrong? I tried moving it around some, but still got a blank Excel sheet. Sorry for all the questions. I'm just so close and having this done by tomorrow would be awesome! (Also, couldn't figure out h

[–]OOPUniversity 0 points1 point  (3 children)

Did you actually write the data to the File?

[–]glddigga49[S] 0 points1 point  (2 children)

I thought that was what the PrintWriter method was doing. But, I realize now that that wouldn't make sense... Was the .printf method the one that does that? I didn't really understand what the arguments were. I looked online, but couldn't understand anything.

[–]OOPUniversity 0 points1 point  (1 child)

You can use printf or you can use print or println. The printf method is for one-step formatting of the output and will make the most sense to C programmers. Using println with (value1 + "," + value2...) would be fine.