Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public class PrvKolokvium_Grupa2 {
  2. public void copyLargeTxtFiles(String from, String to, long size) throws IOException{
  3. File f = new File(from);
  4. File t = new File(to);
  5.  
  6. if(!f.exists()){
  7. System.out.println("Ne postoi");
  8. return;
  9. }
  10. if(!t.exists()){
  11. t.mkdirs();
  12. }
  13.  
  14. File[] files = f.listFiles();
  15. for (File file : files) {
  16. if(file.getName().endsWith(".txt") && file.length() > size){
  17. FileInputStream fis = null;
  18. FileOutputStream fos = null;
  19.  
  20. try {
  21. fis = new FileInputStream(file);
  22. File newFile = new File(to, file.getName());
  23. fos = new FileOutputStream(newFile);
  24. int b;
  25. while((b = fis.read()) == -1){
  26. fos.write(b);
  27. }
  28.  
  29. } catch (Exception e) {
  30. // TODO: handle exception
  31. }finally{
  32. if(fis != null){
  33. fis.close();
  34. }
  35. if(fos != null){
  36. fos.flush();
  37. fos.close();
  38. }
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement