Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O and serialization  RSS feed

 
Jo Shoe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never posted to a forum, so if I am not doing something right please let me know. I am trying to do a review for a mid-term this week. I figured out the other 21 but I have 2 problems I cannot solve. I am unable to figure what needs to go into the areas marked with instructions. If I could get a hint. I have tryed for the last 4 days ... and don't know where else to go. These practice exercises are at the end of the chapter on I/O and serialization. I cannot find an example in the book to try to understand. I also looked all over on the internet to find a hint. Thank you.

Jo

class Complete3_1 {
char[] someChars;
public void initialize( String fileName,
int maxCharCount ) {

// fINISH THE INITIALIZE METHOD SO THAT IT FILLS THE CHARACTER ARRAY WITH CHARACTERS READ FROM THE SPECIFIED FILE

}
public String toString() {
return new String( someChars );
}
public static void main( String[] args ) {
if ( args.length >= 1 ) {
Complete3_1 a = new Complete3_1();
a.initialize( args[0], 100 );
System.out.println( a );
} else {
System.out.println( "A filename is required." );
}
}
}




package questions.c3;
class Complete3_2 {
String fileChunk;
int value;
public void getInt( String fileName, int start )
{

// FINISH THE getInt METHOD SO THAT IT READS AN INTEGER FROM THE SPECIFIED STARTING POSITION IN THE SPECIFIED FILE

}
public String toString() {
return String.valueOf( value );
}
public static void main( String[] args ) {
if ( args.length >= 1 ) {
Complete3_2 a = new Complete3_2();
a.getInt( args[0], 10 );
System.out.println( a );
} else {
System.out.println( "A filename is required." );
}
}
}


 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

We don't like to do people's homework here, but we're very happy to provide hints and lead you to a solution. So for the first one, you need to open a file and read characters into an array. Do you know how to open a file? Let's see you give this one a try.

For the second one, you need to open a file and "seek" to a given location. This involves opening the file using a different class than you used the first time.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!