Skip to navigation
Copy a file with android
28.06.24
```java File cache_file = new File(cachef.getPath(),"test.jpg"); try { //copyFile(filename.getPath(),cache_file.getPath()); } catch (IOException e) { logme("...error copy"); } private static void copyFile(String sourceFilePath, String destinationFilePath) throws IOException { File sourceFile = new File(sourceFilePath); File destinationFile = new File(destinationFilePath); // Check if the source file exists if (!sourceFile.exists()) { throw new IOException("Source file does not exist: " + sourceFilePath); } // Create InputStream to read from the source file try (InputStream inputStream = new FileInputStream(sourceFile)) { // Create OutputStream to write to the destination file try (OutputStream outputStream = new FileOutputStream(destinationFile)) { // Buffer for efficient copying byte[] buffer = new byte[1024]; int bytesRead; // Read from the input stream and write to the output stream while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } } } } ```
Reply
Anonymous
Information Epoch 1732363874
Using text data files.
Home
Notebook
Contact us