Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FilenameFilter;
- public class HW01_1 {
- public static void main(String [] args)
- {
- if(args.length != 0)
- {
- File file1 = new File (args[0]);
- File [] files = null;
- if(file1.isDirectory())
- files = file1.listFiles(new DirFilter(".txt"));
- long length=0;
- if(files != null)
- {
- for(File file2 : files)
- length += file2.length();
- }
- System.out.println(length/ files.length);
- }
- }
- }
- class DirFilter implements FilenameFilter
- {
- private String check;
- DirFilter(String check) {
- this.check = check;
- }
- @Override
- public boolean accept(File dir, String name) {
- String tmp = new File(name).getName();
- return tmp.endsWith(check);
- }
- }
- import java.io.*;
- import java.nio.charset.StandardCharsets;
- public class HW01_2 {
- public static void main(String[] args) {
- try
- {
- File src = new File("source.txt");
- String text;
- if(!src.exists())
- {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- text = bf.readLine();
- PrintWriter pw = new PrintWriter("source.txt");
- pw.println(text);
- pw.close();
- }
- File dest = new File("destination.txt");
- FileInputStream input = new FileInputStream(src);
- RandomAccessFile dest2 = new RandomAccessFile(dest, "rw");
- dest2.setLength(src.length());
- long position = src.length();
- int b;
- while((b = input.read()) != -1)
- {
- String s = Character.toString((char)b);
- byte [] buff = s.getBytes();
- position -= buff.length;
- dest2.seek(position);
- dest2.write(buff);
- }
- input.close();
- dest2.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement