aspose file tools*
The moose likes Beginning Java and the fly likes deprecated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "deprecated " Watch "deprecated " New topic
Author

deprecated

Mei Jones
Greenhorn

Joined: Oct 19, 2012
Posts: 8
Hi

I was compiling below downloaded and getting Deprecated API and does not get compiled.

io and util still on 1.7 compiler that I have on my PC. Not sure what else compiler compliaing about..

Appreciate any thoughts.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

First, let's put your code inside code tags, to make it readable:


There, that's better.

Second, your code DOES get compiled. It give you (well, it give me) a warning:

C:\slop>javac FileTest.java
Note: FileTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

but the class file is there. It even runs:

C:\slop>java FileTest trk.hl7
getName() = trk.hl7
getAbsoluteFile().getName() = trk.hl7
exists() = true
canRead() = true
canWrite() = true
getPath() = trk.hl7
getAbsolutePath() = C:\slop\trk.hl7
getCanonicalPath() = C:\slop\trk.hl7
getAbsoluteFile() = C:\slop\trk.hl7
toURL() = file:/C:/slop/trk.hl7
toURI() = file:/C:/slop/trk.hl7
getParent() = null
isAbsolute() = false
isDirectory() = false
isFile() = true
isHidden() = false
lastModified() = 1310499558269 = Tue Jul 12 14:39:18 CDT 2011
length() = 3589


The warning it gave you tells you what you should do:

Note: Recompile with -Xlint:deprecation for details.

Basically, you are being told you are using a method that is no longer supported - there is a new, better one you should be using.

C:\slop>javac -Xlint FileTest.java
FileTest.java:30: warning: [deprecation] toURL() in java.io.File has been deprecated
System.out.println("toURL() = " + f.toURL());
^
1 warning

Checking the API for the toURL method shows this:

toURL()
Deprecated.
This method does not automatically escape characters that are illegal in URLs. It is recommended that new code convert an abstract pathname into a URL by first converting it into a URI, via the toURI method, and then converting the URI into a URL via the URI.toURL method.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mei Jones
Greenhorn

Joined: Oct 19, 2012
Posts: 8
it is frustrating I am just using text pad to write the code. Apologize..

Secondly, looks like the method exists() on class "File" does not look for files (such as .doc, .xls etc) it checks only sub directory.
This code
boolean exists = f.exists();
System.out.println("exists() = " + exists);

This prints exists only if there are sub directories under it.

How do I modify to check for any "files" inside the directory ?

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

deprecated means, we are not deleting this method/class/ whatever but we have a new and improved version which you should use.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

Mei Fdo wrote:it is frustrating I am just using text pad to write the code. Apologize..

No need to apologize - there is a lot to learn when you are just starting. the code tags are a feature of this site, not what you use to write your code with. Check out this article. There are probably some other articles you should read found here as well to get an idea how this site works best.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deprecated