Trying to use the Filereader.toStringArray(String filename) in a SandBox.
What is the import library for this? Since this isn’t the java.io version, I am assuming this is in org.code somewhere.
Trying to use the Filereader.toStringArray(String filename) in a SandBox.
What is the import library for this? Since this isn’t the java.io version, I am assuming this is in org.code somewhere.
Hi @sheck, thank you for posting this to the forum. After looking around for a bit I unfortunately came up empty. Does import java.io.FileReader;work? I’ll do some more digging and ask around.
java.io does have a FileReader class, but I think Code.org created their own FileReader with the toXXXXArray methods. So I assume the code.org created FileReader class will be hanging off org.code somewhere. I tried some guesses (like import org.code.io.FileReader) but no joy.
I wish code.org would document all of the libraries the use the JavaLab documentation.
For reference, this is the java.io.FileReader documentation.
FileReader (Java Platform SE 8 ) (oracle.com)
Hi Kevin,
I’m sorry you are having this issue! It is definitely frustrating to not know what code is being run and from where for the FileReader. I wanted to reply back to you that I am looking into the issue, and I believe that you are correct, that Code.org created their own FileReader class. In previous years it was part of the java files included in levels that needed it-- Students used it but did not edit the FileReader class. I believe that this year has the FileReader included as a java file that works in the background. I have reached out for some clarification on this.
Thank you for bringing this issue to light,
Lindsay
Hi, to circle back with info on the FileReader class-
The link I shared above to the previous years lessons does show the code for the FileReader class. The class was moved to be a hidden support class so that students can focus on the learning objectives in the lesson, working with the arrays after the FileReader creates them from the text files. The curriculum team is considering how to make the FileReader class more clear in this unit. Thank you, Kevin, for bringing this up!
I gave my students the Sandbox for Unit 3 (objects first) to practice with before the Unit project. They are trying to use the FileReader but cannot access it. I gave them the FileReader.java file from a previous post, but it doesn’ t have the toStringArray method that is needed. Is there another version we can give to the students?
@oneils - Shaunna are you looking for something like this?
This is from Unit 3 Lesson 9 Level 7A (teacher example) of the Objects First Curriculum.
Please let us know if this helps.
Sylvia
That’s not quite it. There is a FileReader class that is hidden from the students, but can be used to read files. It is usable from the assignments, but not from the Sandbox. I pulled in some code from what was posted from an earlier version of the lessons, but it didn’t have the toStringArray or the toIntArray in it. I ended up coding one together with my students, using the basics from the FileReader class to handle the File, Scanner and ioException handling.
@oneils I will take a look, but those methods may not be available to anyone. I have asked Lindsay to help investigate as well.
Hi, this level from the 2022 curriculum might help, it has more methods for the different data types. Upon a quick look, I’m seeing a few differences from what students are using this year. The name of the methods are slightly different- getIntData vs. toIntArray. Also, the old FileReader class had students create a FileReader object and call methods on that object. The current FileReader class has static methods that are called on the name of the class itself, without needing to create a FileReader object. This could be a learning experience for students, or if that will create more confusion than you want, I have another idea. You could give students the project level from last year to practice in, it has the FileReader in the background. Here is a link to the Unit 3 project from the 2024-25 curriculum.
I’m sorry you are having these issues, your students are lucky to have an instructor that is ready to code the FileReader class with them in class, I’m sure that was a learning experience!
Best,
Lindsay
Hi Everyone,
Here is a project that has the up-to-date FileReader class included. I hope this helps and I agree with @lindsay.davis that your students are lucky to have an instructor like you!
-Ken
Lindsay,
I’m using the Objects-First CSA curriculum. We are in Unit 3 - Arrays and Algorithms. In Lesson 6 they are taught how to read text files on their own using File and Scanner. But then the lessons switch to using FileReader, including the unit project. Are students not going to need to understand how to read files without the FileReader on the AP test? Is there another unit that practices the File and Scanner use beyond this one Lesson 6 in Unit 3?
@oneils Shaunna - here is what the CED states regarding the use of the Scanner class.
The following Scanner methods and
constructor—including what they do and when they are used—are part of the Java Quick Reference:
Scanner(File f) is the Scanner
constructor that accepts a File for
reading.
• int nextInt() returns the
next int read from the file or input
source if available. If the next int does
not exist or is out of range, it will result in
an InputMismatchException.
• double nextDouble() returns
the next double read from the file
or input source. If the next double
does not exist, it will result in an
InputMismatchException.
• boolean nextBoolean() returns
the next boolean read from the file
or input source. If the next boolean
does not exist, it will result in an
InputMismatchException.
• String nextLine() returns the
next line of text as a String read
from the file or input source; can return
the empty string if called immediately
after another Scanner method that is
reading from the file or input source.
• String next() returns the next
String read from the file or input source.
• boolean hasNext() returns true
if there is a next item to read in the file or
input source; returns false otherwise.
• void close() closes this scanner.
X EXCLUSION STATEMENT—Accepting input
from the keyboard is outside the scope of the AP
Computer Science A course and exam.
Please let us know if you have any other questions.
Sylvia
Hi Shaunna,
Working with the Scanner shows up throughout the curriculum, for example, in the second semester there are several lessons that use it to create Array Lists of words from a paragraph.
My plan for this new content this year is to follow the curriculum from Code. and then make sure I assign AP classroom practice on these topics during out exam review time to be sure students have seen the content in the context that they will see it on the exam.
Best,
Lindsay