11.10 java jobs

 

 

text3 Package; 

Import java.io.File; 
Import java.io.IOException; 
Import java.nio.file.Files; 

public class filesize { 
	
Double size = 0.0; 
size // computes the file or folder, the unit MB 
public Double getSize (file file) { 
	Double = n-file.length (); 
if Analyzing // file exists 
iF (File.Exists ()) { 
(! file.isFile ()) {iF 
// Get file size 
file [] fl = file .listFiles (); 
Double SS = 0; 
for (File F: FL) 
SS + = getSize (F); 
return SS; 
} 
the else { 
Double = n-SS / 1024/1024; 
System.out.println (file.getName ( ) + ":" + SS + "MB"); 
return SS; 
} 
} 
the else {  
System.out.println ( "file or folder does not exist");
return 0.0; 
} 
}
public static void main(String[] args) throws IOException{
filesize fd = new filesize();
String path = "F:\\xiaoshuo"; 
File f = new File(path);
double all = fd.getSize(f);
System.out.println("All: "+all+"MB");
}
}

  

 

 

 

 

 

text3 Package Penalty for; 

Import java.io.File; 
Import java.io.InputStream; 
Import java.io.OutputStream; 
Import java.io.FileInputStream; 
Import java.io.FileOutputStream; 
// write a file encryption program from the command line plus complete decryption 
public class filepass { 
 Private static int numOfEncAndDec = Final. 1; // cryptographic key 
 private static int dataOfFile = 0; // byte in the file 

 public static void main (String [] args) { 
  file = new new srcFile file ( "F: \\ xiaoshuo \\ English version of Gone with the Wind .txt"); // initialization file 
  file encFile = new file ( "F : \\ xiaoshuo \\ jiami.txt"); // encrypted file 
  file decFile = new file ( "F: \\ xiaoshuo \\ jiemi.txt"); // file to decrypt 
  
  the try { 
    
      EncFile (srcFile, decFile); // cryptographic operations 
 
      decFile (decFile, encFile);
  } the catch (Exception E) { 
   e.printStackTrace (); 
  } 
 } 
 Private static void EncFile (File srcFile, File encFile) throws Exception { 
  IF {(srcFile.exists ()!) 
   System.out.println ( "Source File Not exixt"); 
   } 
  IF ( ! encFile.exists ()) { 
   System.out.println ( "Created the encrypt file"); 
   encFile.createNewFile (); // if no encrypted file, create a new encrypted file 
  } 
  the InputStream new new FIS = the FileInputStream (srcFile); 
  the OutputStream fos a FileOutputStream new new = (encFile); 
  
  the while ((dataOfFile = fis.read ())> -. 1) {// read the contents of the file when 
   fos.write (dataOfFile ^ numOfEncAndDec); // write the encrypted contents read out the 
  } 
  fis.close (); 
  fos.flush (); 
  fos.close (); 
 } 
 Private static void decFile (File encFile, File decFile) throws Exception {
  {IF (encFile.exists ()!) 
   System.out.println ( "encrypted file does not exist"); 
  } 
  IF {(decFile.exists ()!) 
   System.out.println ( "need to create a decrypted file"); 
   decFile.createNewFile (); 
  } 
  the InputStream new new FIS = the FileInputStream (encFile); 
  the OutputStream a FileOutputStream fos = new new (decFile); 
  
  the while ((dataOfFile = fis.read ())> -. 1) { 
   fos.write (dataOfFile ^ numOfEncAndDec); 
  } 
  fis.close (); 
  fos.flush (); 
  fos.close (); 
 } 

}

  

 

 

 

 

text3 Package; 

Import java.io.File; 
Import a java.io.FileInputStream; 
Import java.io.FileNotFoundException; 
Import java.io.FileOutputStream; 
Import java.io.IOException; 

public class filefeng { 
public static void main (String [] args) { 
// call cutFile () function parameters were descendants (the original large file, the path of small files stored after cutting, cutting provisions memory size) 
cutFile ( "F: \\ \\ xiaoshuo English version of Gone with the Wind .txt" , "F.: \\ \\ cunfang.txt xiaoshuo", 20 is 1024 * 1024 *); 
} 
Private static void cutFile (Yuan String, String XIN, int NUM) { 
the FileInputStream FIS = null; 
File File = null; 
the try { 
FIS the FileInputStream new new = (Yuan); 
File = new new File (Yuan); 
// Create a predetermined size byte array 
byte [] = new new C [NUM] byte; 
int len = 0;
// name for the future to prepare a small file named 
int name = 1; 
// traverse a large file read into the byte array, small files that are written into the corresponding byte array after reading in full 
while ((len = fis.read ( ! c)) = -1) { 
// find each file name and file type of the original large files, small files for the following named prepare 
String NAME2 = file.getName (); 
"." name2.lastIndexOf = int lastIndexOf () ; 
String = name2.substring the substring (0, lastIndexOf); 
String substring2 = name2.substring (lastIndexOf, name2.length ()); 
a FileOutputStream fos = new new a FileOutputStream (XIN + "\\\\" the substring + + "-" + name + substring2); 
small files // write the corresponding byte array 
fos.write (C, 0, len); 
// end resources 
fos.close (); 
name ++; 
} 
} 
the catch (a FileNotFoundException E) { 
E. printStackTrace (); 
} 
the catch (IOException E) {
e.printStackTrace (); 
} 
} 
}

  

Guess you like

Origin www.cnblogs.com/dwx8845/p/11829563.html