Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copying file



Greg,

Thanks for your detailed corrections to my code. I am finishing up a
first course in Java at UH. We did reading and writing to files just
last week, and our teacher did not explain these subtleties. My
concatenating things into one string was purely an experiment on my
part, as my teacher was doing things line-by-line, but your caveat
regarding larger files and memory issues makes lots of sense, even to
me as a beginner. I am also fascinated that you say I copied every
other string. I did have an extra line between the three language
strings, so that's no doubt why I didn't notice. Will check on that.

In any case, I tried the following (showing just the relevant part):

// Create input file and stream
File f1 = new File(sSourceFile);
FileInputStream fis = new FileInputStream(f1);

// Create output file and stream
File f2 = new File(sDestinFile);
FileOutputStream fos = new FileOutputStream(f2);

// Read ?1 byte? ?16-bits? one at a time and write to output file
int c;
while ((c = fis.read()) != -1) {
fos.write(c);
}

// Create output files, streams, and writers
fis.close();
fos.close();

This approach (found where you suggested in the Java tutorial) is
obviously more streamlined than what I was doing. But TextEdit still
failed to open the new rtf file!!! The file and its icon appear in my
Build folder next to the original, but the open fails.

Just to make sure that the TextEdit was properly encoded as UTF8, I
selected that for Save encoding in Preferences, rather than
"automatic." Still didn't work.

In the meantime, my Project Builder project file icon has disappeared!
I remember that learning C wreaked havoc on my OS 8 way back when I
started learning C. Is Java going to do the same thing? To be safe,
should I partition my drive to have, say, a "beginner's programming"
partition apart from everything else? Is this a common problem?

Thanks,
Daniel
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.