I have been having this weird problem with this small part of code:

if(isURL)
File audio = new File(name);
else
URL audio = new URL(name);

Now isURL is a pre-declared boolean and name is a pre-declared string. I have all the proper imports but for some reason or another it tells me that my declaritions of the variables are not statements; if I put them in brackets it does the same thing but if I take them out of the if-else statement, it works fine (well if you change the name of one of the variables). Anybody have any ideas on this issue.

Recommended Answers

All 3 Replies

The entire thing you have there is not a valid Java statement.
What are you trying to achieve anyway? The variable would (were this to compile) be lost anyway as soon as it completed.

oh I totally forgot about scope within an if statement, that would explain my problem.

Basically what I'm trying to do is allow the user to input a path (a file path {without having to be file:// in front of it} or a URL path). The program figures out whether it is a file or a URL and then sets the isURL variable to true if the input was found to be a URL. Now I want to figure out what type of variable it is so I can handle the file or URL while having the same variable name.

Can you thing of a way to do this or should I just append file:// to a file Input string and just use the URL variable exclusively?

You can always turn a File into a URL, so create a File and return the result of the toURl method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.