We can taken the folder as inputstream and move to another ?

i need to move all content in some folder and move to another

we can ?

import java.io.*;

publicclass TestOut{

publicstaticvoid main(String args[]){

try{

File file=new File("c:\\from");

InputStream fis=new FileInputStream(file);

File file2=new File("c:\\to");

OutputStream fos=new FileOutputStream(file2);

while(fis.read()!=-1)fos.write(fis.read());

}catch(Exception e){

e.printStackTrace();

}

}

}

i don't know if any person have idea to move content folder to another

thanks

[1277 byte] By [javaskilleda] at [2007-11-15]
# 1
Just rename the folder?
ejpa at 2007-7-12 > top of java,Core,Core APIs...
# 2

thanks for replay but

when rename the folder already exsit

will be return flase this imporve we can't rename folder if the name folder already exsit

you have any idea for that ?

the scenario is i need rename the folder to another but when exsit thee folder same the name need to renamed will be not rename

i think this good imagine

bye

javaskilleda at 2007-7-12 > top of java,Core,Core APIs...
# 3

> thanks for replay

Do you mean 'reply'?

> but when rename the folder already exsit

> will be return flase

If you mean 'false', correct

> this imporve we can't rename

> folder if the name folder already exsit

> you have any idea for that ?

>

> the scenario is i need rename the folder to another

> but when exsit thee folder same the name need to

> renamed will be not rename

> i think this good imagine

I don't understand a word of this.

ejpa at 2007-7-12 > top of java,Core,Core APIs...
# 4

sorry about my english

any way

the real problem is when rename file to another name may be have same folder have same (when find the same folder have same name we can't renam the old folder)

ex)

mainFolder ==contains==> oldFolder 'and' newFolder

we can't rename the oldFolder to newFolder becouse have he already exsit

-

thanks

javaskilleda at 2007-7-12 > top of java,Core,Core APIs...
# 5
just delete the destination older before renaming the source foldermatfud
matfuda at 2007-7-12 > top of java,Core,Core APIs...
# 6
ok but i needed the destanation folder
javaskilleda at 2007-7-12 > top of java,Core,Core APIs...
# 7
OK well you've got the basics of it there in your first post. Now all you need to do is look up File.listFiles() to see how to get all the files in a directory and you're away.
ejpa at 2007-7-12 > top of java,Core,Core APIs...
# 8

iam write this program

to rename folder

import java.io.File;

import java.io.UnsupportedEncodingException;

import java.util.ResourceBundle;

/**

* This class represent renaming the file from

* garbage name to arabic name

*

* @author Moayad Fawzi Abu Jaber

* @version 1.0

*

*/

public class RenameFiles{

/**

* Main method to excute the programe will be call

* the file and retrive the rootFile name

* @param arags array of string to enter from comand line

*

*/

public static void main(String args[]){

ResourceBundle recourceBundle=ResourceBundle.getBundle("selectRoot");

String rootName=recourceBundle.getString("root");

File rootFile=new File(rootName);

traceFolder(rootFile);

}

/**

* method will be represent the root folder

* @param roothFile file object created in main method and passed here

*

*/

public static void traceFolder(File rootFile){

File[] files=rootFile.listFiles();

for(int i=0;i<files.length;i++){

if(files[i].isDirectory()){

rename(files[i]);

}

}

}

/**

* here will be rename the folder and recall itself (recarsive)

* @param file will be pass from traceFolder method

*

*/

public static void rename(File file){

String oldName=file.getPath();

byte[] oldBytes=null;

String newName=null;

try{

oldBytes=oldName.getBytes("windows-1252");

newName=new String(oldBytes,"windows-1256");

}catch(UnsupportedEncodingException e){

System.out.println("Error En get Bytes method");

}

file.renameTo(new File(newName));

//here need to speartion the recursive

{

File[] files=file.listFiles();

if(files!=null){

for(int i=0;i<files.length;i++){

if(files[i].isDirectory()){

rename(files[i]);

}

}

}

}//end block of speartion

}

}

now i need now rename some folder ('deleted'==>'trash' ,'outbox'==>'sent')

but some times is found the trash or sent

and need the files in two folder idon't need lose anything

javaskilleda at 2007-7-12 > top of java,Core,Core APIs...
# 9

If you need the destination folder as you stated above you can't just rename directories, you have to process the individual files. You could try to rename the files into the target directory actually, but renames across file systems don't work, or renames when the target file exists, so you'll have to decide what to do in each of those cases. They probably both resolve to copying the data as in your first posting.

ejpa at 2007-7-12 > top of java,Core,Core APIs...
# 10
but will take the long time when process each files into the folder and have can't moved will thrwon exception says is not found the distination file
javaskilleda at 2007-7-12 > top of java,Core,Core APIs...
# 11

As I said, and as you said yourself, rename won't work in all cases. You don't have any other choice except copying the files, do you?

You can make your file copying loop significantly faster by reading into and writing from a large byte array instead of reading and writing a single character at a time.

ejpa at 2007-7-12 > top of java,Core,Core APIs...