• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginner to I/O: problem creating file in directory

 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to learn some basic I/O, but having the following problem with the File class:



I don't understand what is going on here. I understood that the File(File, String) constructor created a new File object representing a file with name specified by the second argument, in the directory specified by the first argument. Why is this not happening here?

Thanks very much!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,

In this line

File g = new File(f, "test.txt");

you create your new File object representing the file "test.txt" on your desktop -- but then you never touch this again. Every following line operates on "f", the File object representing your desktop directory. You meant to use "g" everywhere once g is defined, yes? If you replace all your "f"s with "g"s, you'll then actually be probing what you think you are probing, and you will like the answers much better!
 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Err...of course. I was just testing you

How embarrassing! But thanks very much for pointing out my extremely silly mistake. (Better fix those before I think about taking the SCJP!)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!