Click here to Skip to main content
15,915,800 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am able to move files to another folder but the moved file shows 0kb and i'm not able to open it. what could be the mistake.
Java
public static void main(String[] args) throws InterruptedException, IOException 
	{
	   File dest = new File("D:/OCR process");
		for(int j=0;;j++)
		{
        File srce=new File("D:/OCR pipe");
	     File [] files = srce.listFiles();
	     System.out.println("hai");
         if(dest.list().length==0)
         {
           for (int i = 0; i < 1; i++)
	       {
	        	//this line weeds out other directories/folders
        	   
	            System.out.println(files[i]);
	            File sourceFile = new File( "D:\\OCR pipe\\"+files[i].getName());
                File destFile = new File("D:\\OCR process\\"+files[i].getName()); 
                               sourceFile.delete();
                               destFile.createNewFile();
                               
                               System.out.println("This File is error and successfully moved to OCR_ERROR");
                               
                               
               
	       }
           
	      try
	      {
	      Thread.sleep(3000);
	      }
	      catch(InterruptedException i)
	      {
	    	  
	      }
         }
     	}
	}
Posted
Comments
Richard MacCutchan 17-Jun-15 10:46am    
You have not copied anything from the source to the destination.
Rahul Ramakrishnan 17-Jun-15 23:28pm    
so createFile just cerates a file with the same name. thanks for the clarification

1 solution

You only wrote createNewFile — why? As Richard MacCutchan tried to explain to you, you did not copy any data, so how would you expect anything better than 0 kb? :-)

Please use https://docs.oracle.com/javase/tutorial/essential/io/copy.html[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900