मेरे पास एक फ़ाइल example.tar.gz है और मुझे अलग-अलग नाम example_test.tar.gz के साथ किसी अन्य स्थान पर कॉपी करने की आवश्यकता है। मैंविभिन्न स्थान पर फ़ाइल कॉपी और नाम बदलें
private void copyFile(File srcFile, File destFile) throws IOException
{
InputStream oInStream = new FileInputStream(srcFile);
OutputStream oOutStream = new FileOutputStream(destFile);
// Transfer bytes from in to out
byte[] oBytes = new byte[1024];
int nLength;
BufferedInputStream oBuffInputStream =
new BufferedInputStream(oInStream);
while ((nLength = oBuffInputStream.read(oBytes)) > 0)
{
oOutStream.write(oBytes, 0, nLength);
}
oInStream.close();
oOutStream.close();
}
}
जहां
String from_path=new File("example.tar.gz");
File source=new File(from_path);
File destination=new File("/temp/example_test.tar.gz");
if(!destination.exists())
destination.createNewFile();
और फिर
copyFile(source, destination);
साथ की कोशिश की लेकिन यह काम नहीं करता। पथ ठीक है। यह प्रिंट करता है कि फाइल मौजूद है। क्या कोई मदद कर सकता है?
कोशिश 'फ्लश()' अपनी धाराओं से पहले 'पास()' यह ing transferTo को बदल दिया है। –
इस पोस्ट को अपनी पोस्ट में सही करें: 'स्ट्रिंग से_पैथ = नई फ़ाइल ("example.tar.gz"); ' –
@ मोहम्मद, फ्लश को – bestsss