- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
It's a shame the peace treaty didn't address petty, insulting, and ignorant Brits on the internet.
Admin
Well, I would just
But since you want it as an array, you'd have to convert it thusly
Admin
Admin
Sure. In a real program I would worry about closing my file when I'm done with it. I would also have to worry about handling the IOException if it didn't open cleanly, and logging, etc.
But this is just a code fragment to show the method by which I would "open a text file, read it line by line and store it in an array".
Admin
TRWTF is American independence.
Admin
It is: a largely irrelevant date, except as an excuse to use fireworks.
Admin
Java is way too fast to be consider as slow.
Admin
He replied six days later, using Java-based technology.
Admin
String slurpedFile = new Scanner(new File("in.txt")).setDelimiter("\Z").next();
It's not as many lines as perl, but it's simple enough.
Admin
Oh, you wanted it as an array? And with stuff closed? Scanner sc = new Scanner(new File("in.txt")).setDelimiter("\Z"); String[] = sc.next().split("\n"); sc.close();
There. Now it's 50% longer than the perl code. Oh my. Of course, this is not the fastest way of doing things, but we're just slurping a textfile. We'll just cross our legs, hum to ourselves and pretend that the file will fit in RAM. Besides, it's going to run on a java server, and we'll have 64 gigs of RAM to draw from anyway, so who cares?