hi guys,
i m writing a progrma using java.io..
i m unable to move the files into another directory.the following code is working file expect moving the files into another directory.can anyone plz help?
import java.io.*;
import java.sql.*;
class FileVerifier{
public static void main(
String[] args){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc
racle:thin:@"+args[2]+":"+args[3]+":"+args[4],args[0],args[1]);
System.out.println("Connected to Database.");
stmt = con.createStatement();
System.out.println("Created Statement.");
System.out.println("file name is"+args[6]);
File f = new File(args[6]);
String list[] = f.list();
for(int i=0;i<list.length;i++){
File f1 = new File(list[i]);
if(f1.isFile()){
System.out.println(list[i]);
String str="";
BufferedReader bf = new BufferedReader(new FileReader(list[i]));
int j=0;
while((str=bf.readLine())!=null){
if(j>1){
System.out.println("Comparing the String for file "+list[i]);
rs =stmt.executeQuery("SELECT * FROM "+args[5]+" WHERE UPPER(FIRST_ROW)='"+removeSpace(str).toUpperCase()+"'");
System.out.println("Comparing the String for file "+list[i] +" completed.");
if(rs.next()){
File fd = new File(args[8]);
fd.mkdir();
System.out.println("list Created"+list[i]);
///here i m getting problem...
if(f.renameTo(new File(fd,f.getName()))){
System.out.println("Successfully moved the file "+list[i]+" to "+args[8]);
//System.out.println("Successfully moved the file "+list[i]+" to "+args[8]);
}else{
System.out.println("Could not move the file "+list[i]+" to "+args[8]);
}
}else{
stmt.execute("INSERT INTO "+args[5]+" VALUES ('"+list[i]+"','"+removeSpace(str)+"')");
File fd = new File(args[7]);
fd.mkdir();
///here i m getting problem...
if(f.renameTo(new File(fd,f.getName()))){
System.out.println("Successfully moved the file "+list[i]+" to "+args[7]);
}else{
System.out.println("Could not move the file "+list[i]+" to "+args[7]);
}
}
break;
}
j++;
}
}
}
rs.close();
stmt.close();
con.close();
DriverManager.deregisterDriver(new oracle.jdbc.driver.OracleDriver());
}catch(Exception e){
e.printStackTrace();
}finally{
try{
rs.close();
stmt.close();
con.close();
DriverManager.deregisterDriver(new oracle.jdbc.driver.OracleDriver());
}catch(Exception e){
e.printStackTrace();
}
}
}
public static String removeNulls(String str){
String temp="";
char c;
int j = 0;
int len=str.length();
boolean state = true;
for (int i=0;i<len ;i++ ){
c = str.charAt(i);
if(c==32){
if(state){
temp+=" ";
}
//state = false;
}else{
if(c!=0){
temp+=c;
}
//state = true;
}
}
return temp;
}
public static String removeSpace(String str){
String temp="";
char c;
int j = 0;
int len=str.length();
boolean state = true;
for (int i=0;i<len ;i++ ){
c = str.charAt(i);
if(c==32){
if(state){
temp+="";
}
state = false;
}else{
if(c!=0){
temp+=c;
}
state = true;
}
}
return temp;
}
}