A
Alan
I`m trying to create a directory for each URL string read in from
a file. However, one of the directories cannot be created, but the
other can. Neither exist at the start. No exception occurs.
Am I missing something obvious? (I have not used mkdir before.)
I am running on the Windows Vista OS. Thanks, Alan
Output:
http://www.weather.gov/
Creating directory www.weather.gov . . .
Unable to create directory www.weather.gov
http://www.cnn.com/
Creating directory www.cnn.com . . .
Code:
import java.io.*;
import java.lang.*;
public class create_directory
{
public static void main ( String[] args ) throws IOException
{
try
{
BufferedReader infile = new BufferedReader(new
FileReader("URLs.txt"));
String aURL, directory;
while ((aURL = infile.readLine()) != null)
{
System.out.println(aURL);
directory = (aURL.replace("http:","")).replace("/","");
System.out.println("Creating directory " + directory + " . . .");
try
{
if ((new File(directory).mkdir()) == false)
System.out.println("Unable to create directory " + directory);
}
catch (SecurityException e) {e.printStackTrace();}
}
infile.close();
}
catch (IOException e) {e.printStackTrace();}
}
}
a file. However, one of the directories cannot be created, but the
other can. Neither exist at the start. No exception occurs.
Am I missing something obvious? (I have not used mkdir before.)
I am running on the Windows Vista OS. Thanks, Alan
Output:
http://www.weather.gov/
Creating directory www.weather.gov . . .
Unable to create directory www.weather.gov
http://www.cnn.com/
Creating directory www.cnn.com . . .
Code:
import java.io.*;
import java.lang.*;
public class create_directory
{
public static void main ( String[] args ) throws IOException
{
try
{
BufferedReader infile = new BufferedReader(new
FileReader("URLs.txt"));
String aURL, directory;
while ((aURL = infile.readLine()) != null)
{
System.out.println(aURL);
directory = (aURL.replace("http:","")).replace("/","");
System.out.println("Creating directory " + directory + " . . .");
try
{
if ((new File(directory).mkdir()) == false)
System.out.println("Unable to create directory " + directory);
}
catch (SecurityException e) {e.printStackTrace();}
}
infile.close();
}
catch (IOException e) {e.printStackTrace();}
}
}