Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

a Java challenge

Name: Anonymous 2007-10-08 8:24

what's the easiest and cleanest way using only the standard libraries to read the contents of a file into a string (or into memory somewhere)

Name: Anonymous 2007-10-08 8:26

Use a real language

Name: Anonymous 2007-10-08 8:36

from __future__ import with_statement

with open(filename) as f:

Error: Forced indentation of the code.

Name: Anonymous 2007-10-08 9:24

>>1
Python:
file('lol').read()

Java fails sorry sirs

Name: Anonymous 2007-10-08 9:52

>>4
irrelevant. what's the solution?

Name: Anonymous 2007-10-08 9:52

String s = readContentOfAFileIntoAString(file);

Name: Anonymous 2007-10-08 10:19

new FileReader(file).read(a);

Where file is the string with the filename and a is a char array.

Name: Anonymous 2007-10-08 11:31

If you need to do parsing, use a BufferedReader and parse while loading. Reading an entire file into a single String is almost never a good idea.

Name: Anonymous 2007-10-09 7:59


O   A F O T S R I F N M A D N G I K C
K   L                               U
A   L   o r p \ S I S I H T Y L D   F
Y   Y   g                       N   D
Y   O   \   H T S R E W S N A   O   O
O   U   D   E               L   C   G
U   D   O   W A Y Y O U W   U   E   R
F   O   N                   F   S   E
U   N   O T D E M A N D U S E   S   M
Q   T                           I   M
U   K N O W W H A T A M A N P A G   A
I                                   R
N A N G E R E D A E X P E R T P R O G

Name: Anonymous 2007-10-09 7:59

[b]
O   A F O T S R I F N M A D N G I K C
K   L                               U
A   L   o r p \ S I S I H T Y L D   F
Y   Y   g                       N   D
Y   O   \   H T S R E W S N A   O   O
O   U   D   E               L   C   G
U   D   O   W A Y Y O U W   U   E   R
F   O   N                   F   S   E
U   N   O T D E M A N D U S E   S   M
Q   T                           I   M
U   K N O W W H A T A M A N P A G   A
I                                   R
N A N G E R E D A E X P E R T P R O G
[/b]

Name: Anonymous 2007-10-09 8:06

>>9,10
"WHAT A MAN PAG IS"
what's a man pag?
And use / instead of \.
And make it a tad bigger so the whole txt fits.

Name: Anonymous 2007-10-09 10:41

>>7
Right, except that the char array has a certain size, so to get the whole file you need to write a loop.

Name: Anonymous 2007-10-09 12:02

>>9-10
Sorry, you spelled ``FUQIN'' wrong -- you'll have to to redo it.

Name: Anonymous 2007-10-09 12:07

>>12
You can construct the char array using the size of the file. That way you don't need a loop.

Name: Anonymous 2007-10-09 12:25

>>12,14
STOP HAVING A REGULAR DISCUSSION IN THE EXPERT SPIRAL THREAD GOD DAMNIT.

Name: Anonymous 2007-10-09 18:03

>>15
DONT HELP HIM!!!!!!!!!!!!!!!

Name: Anonymous 2010-12-24 4:18

Don't change these.
Name: Email:
Entire Thread Thread List