Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaIO_avgust;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- public class javaIO_avgust {
- public static void main(String[] args) throws IOException {
- String in = "in";
- String out = "out";
- smallFiles(in, out);
- }
- public static void smallFiles(String in, String out) throws IOException {
- File inDir = new File(in);
- File outDir = new File(out);
- rekurzija(inDir, outDir);
- }
- public static void rekurzija(File in, File out) throws IOException {
- File[] fajlovi = in.listFiles();
- long size = 0;
- StringBuilder sb = new StringBuilder();
- BufferedWriter bw = null;
- for (File f : fajlovi) {
- if (f.isFile()) {
- if (f.getName().endsWith(".txt")) {
- size = f.length() / 1024;
- if (size < 100) {
- try {
- bw = new BufferedWriter(new FileWriter(out + "/files.txt"));
- if (f.canRead()) {
- if (f.canWrite()) {
- if (f.canExecute()) {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "RWX" + System.lineSeparator());
- } else {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "RW-" + System.lineSeparator());
- }
- } else {
- if (f.canExecute()) {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "R-X" + System.lineSeparator());
- } else {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "R--" + System.lineSeparator());
- }
- }
- } else {
- if (f.canWrite()) {
- if (f.canExecute()) {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "-WX" + System.lineSeparator());
- } else {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "-W-" + System.lineSeparator());
- }
- } else {
- if (f.canExecute()) {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "--X" + System.lineSeparator());
- } else {
- sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "---" + System.lineSeparator());
- }
- }
- }
- String line = sb.toString();
- bw.write(line);
- } finally {
- if (bw != null)
- bw.close();
- }
- }
- }
- } else if (f.isDirectory()) {
- rekurzija(f, out);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement