// Import for File class
import java.io.*;
class Yes
{
public static void main(String args[]) throws IOException
{
// Create a file object for directory C:\java
File f=new File("D:\\Root\\Test\\");
String s=f.getAbsoluteFile().getParentFile().getName();
System.out.println(s);
// List all the files in the directory, get their File objects.
File[] files=f.listFiles();
// Loop till end of all files
for(int i=0;i<files.length;i++)
{
// Get the name of each file
String name=files[i].getName();
// File should not be a directory, and file should have an extension [this logic also filters folders containing .]
if(!files[i].isDirectory())
{
if(name.contains(".dat")||name.contains(".prm"))
{
// Print the name of the file, and the extension
System.out.println(name);
FileReader in = new FileReader(f+"\\"+name);
FileWriter out = new FileWriter("D:\\Root\\Test2\\"+name);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
}
System.out.println("Moving Done");
}
}
import java.io.*;
class Yes
{
public static void main(String args[]) throws IOException
{
// Create a file object for directory C:\java
File f=new File("D:\\Root\\Test\\");
String s=f.getAbsoluteFile().getParentFile().getName();
System.out.println(s);
// List all the files in the directory, get their File objects.
File[] files=f.listFiles();
// Loop till end of all files
for(int i=0;i<files.length;i++)
{
// Get the name of each file
String name=files[i].getName();
// File should not be a directory, and file should have an extension [this logic also filters folders containing .]
if(!files[i].isDirectory())
{
if(name.contains(".dat")||name.contains(".prm"))
{
// Print the name of the file, and the extension
System.out.println(name);
FileReader in = new FileReader(f+"\\"+name);
FileWriter out = new FileWriter("D:\\Root\\Test2\\"+name);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
}
}
}
System.out.println("Moving Done");
}
}