• 10
  • Locked
Change the TxtInputStream class so that it only works with txt files (* .txt). For example, first.txt or name.1.part3.txt. If a non-txt file is passed (e.g. file.txt.exe), then the constructor should throw an UnsupportedFileNameException. Think about what else you need to do if an exception is throw
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Mike S
Level 26 , Saint Louis, United States
7 February, 18:34
I passed the exercise, but what I wanted to do was something like this:
public TxtInputStream(String fileName) throws FileNotFoundException, UnsupportedFileNameException, IOException {
       if (fileName.endsWith(".txt")) {
       } else {
           throw new UnsupportedFileNameException();
Obviously, it wouldn't let me do that since the super() wasn't in the first line. But creating a new instance of FileInputStream seemed off too. Why is that happening in the constructor? That seems one step beyond what the exercise was asking. I feel like there's something intuitive that I'm missing here...
Level 24 , Wittenberg, Germany
6 June 2021, 16:05
task1814 (UnsupportedFileName) CAVEAT: when the requirements say 'you must also call super.close()' then you have to take that literally (that is, you need to specify the superfluous 'super.' prefix, even though 'close()' without the prefix is exactly the same thing in this case). Perhaps someone should send the programmer who is responsible for this on a Java course for beginners...
Level 25 , Bexleyheath, United Kingdom
5 October 2020, 18:10
Knowing about x.endsWith(String) might have helped.....