• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

io Problem ..moving the files one directory to another

 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}

}
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A problem? What is it?

Your debugging statements conflict with your code. For example:
 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the files are not copying to the directory.i m passing two folder names int the args[7] and args[8].the code works fine for inserting the second line into the database from the file in the current directory and cannot move to another directory ex:args[8]=ok and args[7} nonok directory..i m getting problem while moving the file into the directory..any changes to be made in the above code please let me know
 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i have a zip file which contains 20 files.i want to read the 2nd line of the file which in the zip format.can anyone plz help me?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic