By GokiSoft.com| 10:11 09/09/2021|
Java Advanced

Bài tập nén File & giải nén File & Liệt kê files trong 1 thư mục - winrar - winzip BT1088

Bài 1 :

Tìm 1 file text có kích cỡ lớn sau đó nén dữ liệu vào 1 file khác đặt tên là : vidu.data & Viết giải thuật giải nén file.

Bài 2:

Liệt kê tất cả các file trong 1 thư mục -> Vẽ cấu trúc cây folder

Ví dụ: Nhập vào folder tên là ABC -> Kết quả sẽ như sau

ABC

-- a.txt

-- b.txt

-- AB

---- bb.txt

---- BB

------ cc.png

------ dd.jpg

-- k.doc

Liên kết rút gọn:

https://gokisoft.com/1088

Bình luận

avatar
Nguyễn Hùng Anh [community,C2009G]
2021-09-09 04:33:09


#Main.java


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterInputStream;
import java.util.zip.InflaterInputStream;

public class Main {
    public static void main(String [] args) {
//        zipFile();
        unZipFile();
    }

    static void unZipFile() {
        FileInputStream fis = null;
        InflaterInputStream iis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream("vidu.data");
            iis = new InflaterInputStream(fis);

            fos = new FileOutputStream("vidu2.txt");

            int code;
            while ((code = iis.read()) != -1) {
                fos.write(code);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(iis != null) {
                try {
                    iis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static void zipFile() {
        FileInputStream fis = null;
        DeflaterInputStream dis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream("vidu.txt");
            dis = new DeflaterInputStream(fis);

            fos = new FileOutputStream("vidu.data");

            int code;
            while ((code = dis.read()) != -1) {
                fos.write(code);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (dis != null) {
                try {
                    dis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}


avatar
Lê Sỹ Khai [community,C2009G]
2021-09-09 03:32:52


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nenfilegiainen;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;

/**
 *
 * @author LE KHAI
 */

public class Main {
    public static void main(String[] args) {
        nenFile();
    }
    static void nenFile(){
        FileInputStream fis  = null;
        DeflaterInputStream dis = null;
        FileOutputStream fos = null;
        
        try {
            fis = new FileInputStream("data.txt");
            dis = new DeflaterInputStream(fis);
            fos = new FileOutputStream("vidu.data");
            int a;
            while ((a = dis.read()) != -1) {                
                fos.write(a);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(dis != null){
                try {
                    dis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
}


avatar
Trần Việt Đức Anh [C2010L]
2021-08-19 09:27:36



Bai 2

/*
Liệt kê tất cả các file trong 1 thư mục -> Vẽ cấu trúc cây folder

Ví dụ: Nhập vào folder tên là ABC -> Kết quả sẽ như sau

ABC

-- a.txt

-- b.txt

-- AB

---- bb.txt

---- BB

------ cc.png

------ dd.jpg

-- k.doc
 */
package JAVA_Advanced.Ex1088;

import java.io.File;
import java.util.Scanner;

/**
 *
 * @author Tran Viet Duc Anh
 */
public class Ex2 {
        public static void main(String[] args) {
        String folderName;
        Scanner inp = new Scanner(System.in);
        System.out.println("Nhap vao ten folder");
        folderName = inp.nextLine();
        File folder = new File(folderName);
        if (!folder.exists() || !folder.isDirectory()) {
            System.out.println("Folder does not exist");
            return;
        }
        
        File[] listFiles = folder.listFiles();
        for (File f : listFiles) {
            if (f.isFile()) System.out.println(f.getAbsolutePath());
        }
    }
}


avatar
Võ Như Việt [C2010L]
2021-08-19 04:16:21


#Nen.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Java2Buoi3.BT1088;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;
import java.util.zip.DeflaterOutputStream;

/**
 *
 * @author ADMIN
 */
public class Nen {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Zipfile();
    }
    
    
    static void Zipfile(){
        FileInputStream fis = null;
        DeflaterOutputStream dos = null;
        FileOutputStream fos = null;
        
        try {
            fis = new FileInputStream("test.txt");
            fos = new FileOutputStream ("vidu.data");
            
            dos = new DeflaterOutputStream(fos);
            
            int code;
            while ((code = fis.read()) != -1) {                
                dos.write(code);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Nen.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Nen.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Nen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (dos != null) {
                try {
                    dos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Nen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Nen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
}


#SelectFoder.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Java2Buoi3.BT1088;

import java.io.File;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class SelectFoder {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
                
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten Folder: ");
        String check = sc.nextLine();
        
        File folder = new File(check);
        if (!folder.exists() || !folder.isDirectory()) {
             System.out.println("Folder khong ton tai...");
             return;
        }
        readFile(folder);

    }
    
    public static void readFile(File file){
        if (file.isFile()) {
            System.out.println("--" +file.getName());
        }else if(file.isDirectory()){
            System.out.println("---" +file.getName());
         }
        
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file1 : files) {
                SelectFoder.readFile(file1);
            }
        }
    }
    
}


avatar
hieuvm0512 [community,C2010L]
2021-08-17 18:18:34



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.nenfilevagiainen;

import java.io.File;
import java.util.Scanner;

/**
 *
 * @author vuive
 */
public class bai2 {
    public static void DuyetFile(File file){
        if(file.isFile()){
                System.out.println("--File "+file.getName());
            }else if(file.isDirectory()){
                System.out.println("-Folder "+file.getName());
            }
        if(file.isDirectory()){
            File[] child = file.listFiles();
            for(File chid: child){
                bai2.DuyetFile(chid);
            }
        }
    }
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten folder");
        String f = input.nextLine();
    File folder = new File(f);
    if (!folder.exists() || !folder.isDirectory()) {
            System.out.println("Folder does not exist");
            return;
        }
    DuyetFile(folder);
        
}
}


avatar
hieuvm0512 [community,C2010L]
2021-08-17 18:18:10



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.nenfilevagiainen;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterOutputStream;

/**
 *
 * @author vuive
 */
public class bai1 {
    public static void newFile(){
        String s = "Ghi Chú\n" +
"Thiết Kế Web\n" +
"My CV\n" +
"Liên Hệ\n" +
"Học Viên Tích Cực\n" +
"Đăng Nhập\n" +
"Tìm kiếm\n" +
"\n" +
"\n" +
"Trang Chủ\n" +
"Lập Trình C\n" +
"Frontend\n" +
"Backend\n" +
"Java\n" +
"Android\n" +
"Tools\n" +
"Tuyển Dụng\n" +
"Thiết Kế Web\n" +
"Khác\n" +
"Trang ChủJava AdvancedBài tập nén File & giải nén File & Liệt kê files trong 1 thư mục - winrar - winzip×\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"☰\n" +
"\n" +
" \n" +
"Bài tập nén File & giải nén File & Liệt kê files trong 1 thư mục - winrar - winzip \n" +
"by GokiSoft.com - 20:07 17/08/2021\n" +
"9,370 Lượt Xem\n" +
"Short URL: https://gokisoft.com/1088\n" +
"Bài 1 :\n" +
"\n" +
"Tìm 1 file text có kích cỡ lớn sau đó nén dữ liệu vào 1 file khác đặt tên là : vidu.data & Viết giải thuật giải nén file.\n" +
"\n" +
"Bài 2:\n" +
"\n" +
"Liệt kê tất cả các file trong 1 thư mục -> Vẽ cấu trúc cây folder\n" +
"\n" +
"Ví dụ: Nhập vào folder tên là ABC -> Kết quả sẽ như sau\n" +
"\n" +
"ABC\n" +
"\n" +
"-- a.txt\n" +
"\n" +
"-- b.txt\n" +
"\n" +
"-- AB\n" +
"\n" +
"---- bb.txt\n" +
"\n" +
"---- BB\n" +
"\n" +
"------ cc.png\n" +
"\n" +
"------ dd.jpg\n" +
"\n" +
"-- k.doc\n" +
"\n" +
"THEO DÕI CẬP NHẬT NỘI DUNG HỌC TRÊN YOUTUBE & FACEBOOK\n" +
"\n" +
"\n" +
"	\n" +
"\n" +
"\n" +
"\n" +
"THÔNG TIN LIÊN HỆ\n" +
"\n" +
"Công Ty Cổ Phần Công nghệ ZicZac Việt Nam.\n" +
"\n" +
"Website:  https://ziczacvn.com\n" +
"\n" +
"SĐT:  096 - 70 25 996\n" +
"\n" +
"Email:  ziczacgroup@gmail.com\n" +
"\n" +
"Thiết kế webiste chuyên nghiệp\n" +
"Thiết kế phần mềm quản trị\n" +
"Thiết kế ứng dụng Android\n" +
"Thiết kế ứng dụng IOS\n" +
"Thiết kế Web App\n" +
"Hỗ trợ Digital Marketing\n" +
"Hỗ trợ quảng cáo Google Ads\n" +
"Hỗ trợ quảng cáo Facebook Ads\n" +
"Hỗ trợ SEO Website\n" +
"Tags:\n" +
"T1907A\n" +
"Khoá học java nâng cao\n" +
"Java Advanced\n" +
"02. Thao Tác Files\n" +
"C1907L\n" +
"Today_C1907L\n" +
"C2010G\n" +
"C2010L\n" +
"Today_C2010L\n" +
"Bình luận\n" +
"facebook sharing buttontwitter sharing buttonemail sharing buttonmessenger sharing buttonpinterest sharing buttonwhatsapp sharing buttontumblr sharing buttonlinkedin sharing buttonweibo sharing buttonblogger sharing buttonflipboard sharing buttonwechat sharing buttondigg sharing buttonreddit sharing button\n" +
"\n" +
"\n" +
" \n" +
"PHẢN HỒI BỞI:\n" +
"(1) Trương Công Vinh [T1907A] (2) Minh Nghia [T1907A] (3) Đỗ Văn Huấn [T1907A] (4) thienphu [T1907A] (5) Phạm Ngọc Minh [T1907A] (6) Vũ Việt Đức [C1907L] (7) Nguyễn Hoàng Anh [C1907L] (8) Ngô Quang Huy [C1907L] (9) Hoàng Quang Huy [C1907L] (10) trung [C1907L]\n" +
"CHIA SẺ TỪ LỚP HỌC\n" +
"\n" +
"trung [C1907L]\n" +
"\n" +
"Ngày viết: 16:27 03/05/2020\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package infdef;\n" +
"\n" +
"import java.io.File;\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.DeflaterInputStream;\n" +
"import java.util.zip.InflaterInputStream;\n" +
"import java.util.zip.InflaterOutputStream;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author prdox\n" +
" */\n" +
"public class Main {\n" +
"    public static void main(String[] args) {\n" +
"        String str = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis accumsan turpis sed ipsum tincidunt, et vulputate nisi viverra. Aliquam a cursus ligula. Duis luctus nunc nisl. Etiam sit amet porta nibh. Duis commodo dolor nec euismod commodo. Morbi lobortis tortor quis odio laoreet dapibus. Quisque nibh velit, ullamcorper a ornare at, egestas sit amet felis. Quisque aliquam ultricies augue, et iaculis leo molestie eu. Nullam a gravida urna, sed blandit ex. Cras a rutrum tellus. Donec nunc sem, aliquam nec ex sit amet, malesuada placerat lorem. Maecenas sit amet ligula odio. Maecenas dignissim bibendum dui a gravida. Praesent suscipit tincidunt ligula, eu sodales mauris vestibulum id. Vivamus accumsan nibh orci, hendrerit placerat enim porttitor a. Pellentesque finibus gravida ante luctus pulvinar.\\n\"\n" +
"                + \"\\n\"\n" +
"                + \"Aliquam nec sapien quis ante iaculis ultrices dignissim sed magna. Vivamus dolor turpis, suscipit vitae eros sed, eleifend lobortis est. Aenean quam augue, consequat quis justo ac, vehicula porta quam. Maecenas convallis mi sit amet varius maximus. Sed lacinia diam nulla, eget mollis enim tristique quis. Vestibulum viverra rutrum nulla, id gravida dui lacinia et. Quisque mattis turpis sit amet varius rhoncus. Aliquam id mi id metus lobortis dignissim. Aenean in elementum ante. Nulla lacinia purus a arcu auctor feugiat. Nulla lacinia lorem at dolor luctus, at iaculis sapien maximus. Vivamus vel purus non orci tempor commodo. Praesent tristique eros vel mi bibendum varius. Vivamus placerat, diam ut porttitor sagittis, est mauris ornare mi, non ultricies nisl odio non justo. Nulla sollicitudin turpis ut nibh sagittis eleifend. Nunc rutrum diam vel tellus congue tempor.\\n\"\n" +
"                + \"\\n\"\n" +
"                + \"Praesent egestas magna vitae sem dapibus pretium. Donec vel pretium erat, nec maximus ante. Donec dictum fringilla ex, ut iaculis velit pharetra tristique. Cras rhoncus, dolor vitae aliquet porta, magna nisi vulputate ipsum, eu consectetur mauris orci sodales dui. In maximus sagittis rutrum. Nunc vulputate sapien quis nisi sodales, vitae lobortis enim molestie. Morbi eget finibus dolor. Sed lectus ligula, lacinia sit amet ullamcorper eget, efficitur sed mauris. Pellentesque congue finibus tellus, vel maximus est vehicula a. Aliquam eget rutrum dui. Phasellus porttitor fermentum ligula blandit dapibus. Praesent tristique facilisis vehicula. Nulla ut dictum sem, sed luctus est. Phasellus lacinia condimentum urna at gravida. Suspendisse potenti. Vestibulum scelerisque porttitor feugiat.\\n\"\n" +
"                + \"\\n\"\n" +
"                + \"Nunc feugiat pharetra ex at congue. Etiam eget velit libero. Mauris scelerisque et nisi et lobortis. Phasellus hendrerit tortor non tristique volutpat. Pellentesque non nibh id lorem suscipit sagittis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis vitae consectetur neque.\\n\"\n" +
"                + \"\\n\"\n" +
"                + \"Maecenas dui nisl, mattis eget mattis quis, suscipit ac risus. Donec dictum ligula in libero porta pulvinar. Sed consequat erat quis lacus bibendum consequat. Nam interdum, ante sed condimentum dignissim, erat urna imperdiet magna, at ornare elit nisl ut sapien. Proin sed arcu suscipit, mollis nisl eget, elementum diam. Donec bibendum, elit eu lacinia dignissim, mauris turpis convallis eros, sit amet tempor nisl tortor ac sem. In hac habitasse platea dictumst. Aenean eget ultricies mauris. Maecenas nec hendrerit nisi. Duis sed posuere eros, in bibendum odio. Proin id vulputate diam, vitae fermentum turpis. Etiam vel urna at elit ullamcorper suscipit id ac risus. \";\n" +
"        FileOutputStream fos = null;\n" +
"        try {\n" +
"            fos = new FileOutputStream(\"longString.txt\");\n" +
"            byte[] b = str.getBytes();\n" +
"            fos.write(b);\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            try {\n" +
"                if (fos != null) fos.close();\n" +
"            } catch (IOException ex) {\n" +
"                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"            }\n" +
"        }\n" +
"        \n" +
"        //Deflate file -> vidu.data\n" +
"        FileInputStream fis = null;\n" +
"        DeflaterInputStream dis = null;\n" +
"        fos = null;\n" +
"        try {\n" +
"            fis = new FileInputStream(\"longString.txt\");\n" +
"            dis = new DeflaterInputStream(fis);\n" +
"            fos = new FileOutputStream(\"vidu.data\");\n" +
"            int code;\n" +
"            while ((code = dis.read()) != -1){\n" +
"                fos.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if (fis != null) {\n" +
"                try {\n" +
"                    fis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if (dis != null) {\n" +
"                try {\n" +
"                    dis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if (fos != null) {\n" +
"                try {\n" +
"                    fos.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"        \n" +
"        //Inflate file -> vidu.data\n" +
"        fis = null;\n" +
"        InflaterOutputStream ios = null;\n" +
"        fos = null;\n" +
"        try {\n" +
"            fis = new FileInputStream(\"vidu.data\");\n" +
"            fos = new FileOutputStream(\"extract_vidu.txt\");\n" +
"            ios = new InflaterOutputStream(fos);\n" +
"            int code;\n" +
"            while ((code = fis.read()) != -1){\n" +
"                ios.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if (fis != null) {\n" +
"                try {\n" +
"                    fis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if (ios != null) {\n" +
"                try {\n" +
"                    dis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if (fos != null) {\n" +
"                try {\n" +
"                    fos.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"        \n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package file;\n" +
"\n" +
"import java.io.File;\n" +
"import java.nio.file.Path;\n" +
"import java.util.Scanner;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author prdox\n" +
" */\n" +
"public class listFile {\n" +
"\n" +
"    public static void main(String[] args) {\n" +
"        String folderName;\n" +
"        Scanner inp = new Scanner(System.in);\n" +
"        System.out.println(\"Nhap vao ten folder\");\n" +
"        folderName = inp.nextLine();\n" +
"        File folder = new File(folderName);\n" +
"        if (!folder.exists() || !folder.isDirectory()) {\n" +
"            System.out.println(\"Folder does not exist\");\n" +
"            return;\n" +
"        }\n" +
"        \n" +
"        File[] listFiles = folder.listFiles();\n" +
"        for (File f : listFiles) {\n" +
"            if (f.isFile()) System.out.println(f.getAbsolutePath());\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
" \n" +
"\n" +
"Hoàng Quang Huy [C1907L]\n" +
"\n" +
"Ngày viết: 10:21 03/05/2020\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"\n" +
"package lesson4;\n" +
"\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.DeflaterInputStream;\n" +
"\n" +
"public class DeflaterFile {\n" +
"\n" +
"    public static void main(String[] args) {\n" +
"        FileInputStream fis = null;\n" +
"        DeflaterInputStream dis = null;\n" +
"        FileOutputStream fos = null;\n" +
"        try {\n" +
"            fis = new FileInputStream(\"D://C1907L//data.txt\");\n" +
"            dis = new DeflaterInputStream(fis);\n" +
"\n" +
"            fos = new FileOutputStream(\"D://data.zip\");\n" +
"\n" +
"            int code;\n" +
"            while ((code = dis.read()) != -1) {\n" +
"                fos.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if (fis != null) {\n" +
"                try {\n" +
"                    fis.close();\n" +
"\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"\n" +
"            if (dis != null) {\n" +
"                try {\n" +
"                    dis.close();\n" +
"\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"\n" +
"            if (fos != null) {\n" +
"                try {\n" +
"                    fos.close();\n" +
"\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"---------------------------------------------------------------------------\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package lesson4;\n" +
"\n" +
"import java.io.File;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author T480s\n" +
" */\n" +
"public class ListFile {\n" +
"\n" +
"    public static void main(String[] args) {\n" +
"        File folder = new File(\"D://\");\n" +
"        readFile(folder);\n" +
"    }\n" +
"\n" +
"    public static void readFile(File file) {\n" +
"        if (file.isFile()) {\n" +
"            if (file.canRead()) {\n" +
"                System.out.println(file.getAbsolutePath());\n" +
"            }\n" +
"        } else {\n" +
"            System.out.println(\"Folder: \"+file.getAbsolutePath());\n" +
"            File[] lists = file.listFiles();\n" +
"            for (File f : lists) {\n" +
"                ListFile.readFile(f);\n" +
"            }\n" +
"        }\n" +
"        try {\n" +
"            Thread.sleep(100);\n" +
"        } catch (InterruptedException e) {\n" +
"            \n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
"Ngô Quang Huy [C1907L]\n" +
"\n" +
"Ngày viết: 21:41 29/04/2020\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package April29ZipFile;\n" +
"\n" +
"import java.io.File;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author Administrator\n" +
" */\n" +
"public class GetFileName {\n" +
"    public static void main(String[] args) {\n" +
"        File folder = new File(\"C:\\\\Users\\\\Administrator\\\\Documents\\\\NetBeansProjects\\\\AptechJavaAdvanced\");\n" +
"        File[] listOfFiles = folder.listFiles();\n" +
"\n" +
"        for (int i = 0; i < listOfFiles.length; i++) {\n" +
"            if (listOfFiles[i].isFile()) {\n" +
"              System.out.println(\"- File: \" + listOfFiles[i].getName());\n" +
"            } else if (listOfFiles[i].isDirectory()) {\n" +
"              System.out.println(\"- Directory: \" + listOfFiles[i].getName());\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package April29ZipFile;\n" +
"\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.InflaterInputStream;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author Administrator\n" +
" */\n" +
"public class Inflater {\n" +
"    public static void main(String[] args) {\n" +
"        FileInputStream fis = null;\n" +
"        InflaterInputStream iis = null;\n" +
"        FileOutputStream fos = null;\n" +
"        \n" +
"        try {\n" +
"            fis = new FileInputStream(\"vidu.data\");\n" +
"            iis = new InflaterInputStream(fis);\n" +
"            fos = new FileOutputStream(\"output1.txt\");\n" +
"            \n" +
"            int code;\n" +
"            while((code=iis.read())!=-1){\n" +
"                fos.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if( fis != null){\n" +
"                try {\n" +
"                    fis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if( iis != null){\n" +
"                try {\n" +
"                    iis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if( fos != null){\n" +
"                try {\n" +
"                    fos.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package April29ZipFile;\n" +
"\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.DeflaterInputStream;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author Administrator\n" +
" */\n" +
"public class Deflater {\n" +
"    public static void main(String[] args) {\n" +
"        FileInputStream fis = null;\n" +
"        DeflaterInputStream dis = null;\n" +
"        FileOutputStream fos = null;\n" +
"        \n" +
"        try {\n" +
"            fis = new FileInputStream(\"data.txt\");\n" +
"            dis = new DeflaterInputStream(fis);\n" +
"            fos = new FileOutputStream(\"vidu.data\");\n" +
"            \n" +
"            int code;\n" +
"            while((code=dis.read())!=-1){\n" +
"                fos.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if( fis != null){\n" +
"                try {\n" +
"                    fis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if( dis != null){\n" +
"                try {\n" +
"                    dis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if( fos != null){\n" +
"                try {\n" +
"                    fos.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
" \n" +
"\n" +
"Nguyễn Hoàng Anh [C1907L]\n" +
"\n" +
"Ngày viết: 21:28 29/04/2020\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package BaiTapApril29;\n" +
"\n" +
"import java.io.File;\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.DeflaterInputStream;\n" +
"import java.util.zip.InflaterInputStream;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author Redmibook 14\n" +
" */\n" +
"public class NenFileGiaiNenFIleLietKeFile {\n" +
"\n" +
"    public static void main(String[] args) {\n" +
"\n" +
"        FileInputStream fis = null;\n" +
"        DeflaterInputStream dis = null;\n" +
"        FileOutputStream fos = null;\n" +
"        InflaterInputStream iis = null;\n" +
"        try {\n" +
"\n" +
"            fis = new FileInputStream(\"vidu2.txt\");\n" +
"            dis = new DeflaterInputStream(fis);\n" +
"            fos = new FileOutputStream(\"vidu2.zip\");\n" +
"\n" +
"            int codeByte;\n" +
"            while ((codeByte = dis.read()) != -1) {\n" +
"                fos.write(codeByte);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        }\n" +
"\n" +
"        if (fos != null) {\n" +
"            try {\n" +
"                fos.close();\n" +
"            } catch (IOException ex) {\n" +
"                Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"            }\n" +
"        }\n" +
"        try {\n" +
"            fis = new FileInputStream(\"vidu2.zip\");\n" +
"            iis = new InflaterInputStream(fis);\n" +
"            int c;\n" +
"            StringBuilder str = new StringBuilder();\n" +
"            while ((c = iis.read()) != -1) {\n" +
"                str.append((char) c);\n" +
"            }\n" +
"            System.out.println(str);\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        }\n" +
"        if (iis != null) {\n" +
"            try {\n" +
"                iis.close();\n" +
"            } catch (IOException ex) {\n" +
"                Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);\n" +
"            }\n" +
"        }\n" +
"        File fileOrDir = new File(\"C:\\\\Users\\\\Redmibook 14\\\\Documents\\\\NetBeansProjects\\\\FileIn&De_flater\");\n" +
"        traverseDepthFiles(fileOrDir);\n" +
"    }\n" +
"    public static void traverseDepthFiles(File fileOrDir) {\n" +
"        if (fileOrDir.isDirectory()) {\n" +
"            File[] childFile = fileOrDir.listFiles();\n" +
"            for (File value : childFile) {\n" +
"                if (value.isDirectory()) {\n" +
"                    traverseDepthFiles(value);\n" +
"                } else {\n" +
"                    System.out.println(value);\n" +
"                }\n" +
"\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"\n" +
"Vũ Việt Đức [C1907L]\n" +
"\n" +
"Ngày viết: 20:51 29/04/2020\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"Ẩn Code  Copy Code\n" +
"/*\n" +
" * To change this license header, choose License Headers in Project Properties.\n" +
" * To change this template file, choose Tools | Templates\n" +
" * and open the template in the editor.\n" +
" */\n" +
"package lession4;\n" +
"\n" +
"import java.io.FileInputStream;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.io.FileOutputStream;\n" +
"import java.io.IOException;\n" +
"import java.util.logging.Level;\n" +
"import java.util.logging.Logger;\n" +
"import java.util.zip.DeflaterOutputStream;\n" +
"\n" +
"/**\n" +
" *\n" +
" * @author ADMIN\n" +
" */\n" +
"public class Bai1 {\n" +
"    public static void main(String[] args) {\n" +
"        FileInputStream fis = null;\n" +
"        DeflaterOutputStream dos = null;\n" +
"        FileOutputStream fos = null;\n" +
"        \n" +
"        try {\n" +
"            fis = new FileInputStream(\"vidu.txt\");\n" +
"            fos = new FileOutputStream(\"vidu.zip\");\n" +
"            dos = new DeflaterOutputStream(fos);\n" +
"            \n" +
"            int code;\n" +
"            while((code = fis.read()) != -1){\n" +
"                dos.write(code);\n" +
"            }\n" +
"        } catch (FileNotFoundException ex) {\n" +
"            Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } catch (IOException ex) {\n" +
"            Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);\n" +
"        } finally {\n" +
"            if(fis != null){\n" +
"                try {\n" +
"                    fis.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"            if(fos != null){\n" +
"                try {\n" +
"                    fos.close();\n" +
"                } catch (IOException ex) {\n" +
"                    Logger.getLogger(Bai1.class.getName()).log(Level.SEVERE, null, ex);\n" +
"                }\n" +
"            }\n" +
"        }\n" +
"    }\n" +
"}\n" +
"\n" +
"\n" +
"‹\n" +
"1\n" +
"2\n" +
"3\n" +
"›\n" +
"Phân Loại Bài Viết\n" +
"1\n" +
"Gợi Ý & Mục Lục\n" +
"2\n" +
"Lý Thuyết\n" +
"3\n" +
"Bài Tập\n" +
"4\n" +
"Examination & Test\n" +
"5\n" +
"Source Code Chia Sẻ\n" +
"\n" +
" \n" +
"Lọc Bài Viết Theo Chủ Đề\n" +
"1\n" +
"01. Package & Collections\n" +
"2\n" +
"02. Thao Tác Files\n" +
"3\n" +
"03. Thread\n" +
"4\n" +
"04. Java Swing\n" +
"5\n" +
"05. Java Swing + MySQL\n" +
"6\n" +
"06. Examination & Test\n" +
"7\n" +
"07. Java - XML - JSON\n" +
"Danh Sách Bài Học\n" +
"1\n" +
"[Share Code] Share Code - Hướng dẫn tạo dự án WinRar, WinZip, 7Zip toàn tập bằng Java - C2010L\n" +
"2\n" +
"Bài tập nén File & giải nén File & Liệt kê files trong 1 thư mục - winrar - winzip\n" +
"3\n" +
"Java Advanced- BT18 Quản lý thông tin sinh & lưu file (ObjectOutputStream & ObjectInputStream)\n" +
"4\n" +
"[Share Code] Zip File - UnZip File trong Java - Viết chương nén và giải nén File - Lập trình Java nâng cao\n" +
"5\n" +
"Bài tập quản lý sách & lưu thông tin trên Files\n" +
"6\n" +
"File - Quản lý thông tin sinh viên\n" +
"7\n" +
"[Share Code] Tìm hiểu File - FileInputStream & FileOutputStream - BufferedInputStream & BufferedOutStream - ObjectInputStream & ObjectOutputStream - Lập trình Java nâng cao - C2010L\n" +
"8\n" +
"[Share Code] Tìm hiểu File - FileInputStream & FileOutputStream - BufferedInputStream & BufferedOutStream - ObjectInputStream & ObjectOutputStream - Lập trình Java nâng cao\n" +
"9\n" +
"Bài tập - Chương trình quản lý sức khoẻ - Lập trình Java\n" +
"10\n" +
"Java Advanced- Bài tập ôn luyện String, StringBuilder, StringBuffer\n" +
"11\n" +
"Java Advanced- Chương trình quản lý sinh viên bằng HashMap\n" +
"12\n" +
"[Share Code] Tìm hiểu Collections <List, ArrayList, Vector, LinkedList> + <Set, HashSet, TreeSet> + Map <HashMap> - Generic - Lập trình Java - C2010L\n" +
"13\n" +
"[Share Code] Tìm hiểu Collections <List, ArrayList, Vector, LinkedList> + <Set, HashSet, TreeSet> + Map <HashMap> - Generic - Lập trình Java\n" +
"14\n" +
"Bài tập - Giải thuật sắp xếp - Tìm kiếm trong Java - Lập trình Java nâng cao\n" +
"15\n" +
"[Share Code] Tìm hiểu về Exception + StringBuilder - StringBuffer + java.lang package trong Java - Lập trình Java nâng cao.\n" +
"16\n" +
"[Share Code] MultiThread - Sinh số ngẫu nhiên và hiển thị bình phương số ngẫu nhiên & Synchronized trong Java - C2005L\n" +
"17\n" +
"[Share Code] Bài toán đa luồng (MultiThreading in java) đọc File trong Java - C2005L\n" +
"18\n" +
"[Share Code] Overview Java - Bài Tập Quản Lý Sinh Viên - CSDL - Java Swing - C2005L\n" +
"19\n" +
"Phần mềm quản lý sinh viên MySQL + Java - Chương trình quản lý sinh viên MySQL + Java - Lập Trình Java\n" +
"20\n" +
"[Examination] XML/JSON - T2008A\n" +
"21\n" +
"Bài tập - Viết chương trình quản lý sản phẩm - quản lý tin tức - quản lý bán hàng - Lập trình Java\n" +
"22\n" +
"Examination & Test >> Quản lý bán hàng + java console\n" +
"23\n" +
"[Share Code] gson trong Java - Vi dụ json trong java - Bài tập quản lý sản phẩm + json trong Java\n" +
"24\n" +
"Quản lý sinh viên + XML + JSON + MySQL bằng Java\n" +
"25\n" +
"Quản lý thông tin cá nhân Profile bằng java - import + export XML File\n" +
"\n" +
" \n" +
" \n" +
"\n" +
"LOGO\n" +
"Blog chia sẻ kiến thức công nghệ, lập trình và việc làm IT. Hỗ trợ để chúng tôi có thể phát triển thêm nhiều khóa học cho cộng đồng\n" +
"\n" +
"Ví Momo: 0967025996\n" +
"\n" +
"Thiết kế bởi: ziczacvn.com\n" +
"\n" +
"Bạn có câu hỏi? Hãy email chúng tôi tại gokisoft.com@gmail.com\n" +
"\n" +
"    \n" +
"GIỚI THIỆU\n" +
"IMG\n" +
"Giới Thiệu\n" +
"IMG\n" +
"Chính Sách & Nội Quy\n" +
"IMG\n" +
"Liên Hệ\n" +
"BÀI VIẾT MỚI NHẤT\n" +
"IMG\n" +
"[Share Code] Share Code - Hướng dẫn tạo dự án WinRar, WinZip, 7Zip toàn tập bằng Java - C2010L\n" +
"17-08-2021\n" +
"IMG\n" +
"Bài tập nén File & giải nén File & Liệt kê files trong 1 thư mục - winrar - winzip\n" +
"17-08-2021\n" +
"IMG\n" +
"Java Advanced- BT18 Quản lý thông tin sinh & lưu file (ObjectOutputStream & ObjectInputStream)\n" +
"16-08-2021\n" +
"Copyright © 2019 All rights reserved";
        FileOutputStream fos = null;
        
        try {
            fos = new FileOutputStream("E:\\Work\\JAVA\\Netbean\\nenfilevagiainen\\bruh.txt");
            byte[] data = s.getBytes("utf8");
            fos.write(data);
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
    public static void deflater(){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        DeflaterInputStream dis = null;
        try {
            fis = new FileInputStream("E:\\Work\\JAVA\\Netbean\\nenfilevagiainen\\bruh.txt");
            dis = new DeflaterInputStream(fis);
            fos = new FileOutputStream("E:\\Work\\JAVA\\Netbean\\nenfilevagiainen\\bruh.data");
            int code;
            while((code = dis.read())!=-1){
                fos.write(code);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(dis!=null){
                try {
                    dis.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
     
    }
    public static void doCopy(InputStream is, OutputStream os) {
        int oneBytes;
        try {
            while ((oneBytes = is.read()) != -1) {
                os.write(oneBytes);
            }
        
    }   catch (IOException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public static void inflater(){
        FileInputStream fis = null;
        InflaterOutputStream ios = null;
        FileOutputStream fos = null;
        
        try {
            fis = new FileInputStream("E:\\Work\\JAVA\\Netbean\\nenfilevagiainen\\bruh.data");
            fos = new FileOutputStream("E:\\Work\\JAVA\\Netbean\\nenfilevagiainen\\done.txt");
            ios = new InflaterOutputStream(fos);
            int code;
            while((code = fis.read())!=-1){
                ios.write(code);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if(ios!=null){
                try {
                    ios.close();
                } catch (IOException ex) {
                    Logger.getLogger(bai1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    public static void main(String[] args){
        newFile();
        deflater();
        inflater();   
    }
}


avatar
trung [C1907L]
2020-05-03 09:27:12



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package infdef;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.InflaterOutputStream;

/**
 *
 * @author prdox
 */
public class Main {
    public static void main(String[] args) {
        String str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis accumsan turpis sed ipsum tincidunt, et vulputate nisi viverra. Aliquam a cursus ligula. Duis luctus nunc nisl. Etiam sit amet porta nibh. Duis commodo dolor nec euismod commodo. Morbi lobortis tortor quis odio laoreet dapibus. Quisque nibh velit, ullamcorper a ornare at, egestas sit amet felis. Quisque aliquam ultricies augue, et iaculis leo molestie eu. Nullam a gravida urna, sed blandit ex. Cras a rutrum tellus. Donec nunc sem, aliquam nec ex sit amet, malesuada placerat lorem. Maecenas sit amet ligula odio. Maecenas dignissim bibendum dui a gravida. Praesent suscipit tincidunt ligula, eu sodales mauris vestibulum id. Vivamus accumsan nibh orci, hendrerit placerat enim porttitor a. Pellentesque finibus gravida ante luctus pulvinar.\n"
                + "\n"
                + "Aliquam nec sapien quis ante iaculis ultrices dignissim sed magna. Vivamus dolor turpis, suscipit vitae eros sed, eleifend lobortis est. Aenean quam augue, consequat quis justo ac, vehicula porta quam. Maecenas convallis mi sit amet varius maximus. Sed lacinia diam nulla, eget mollis enim tristique quis. Vestibulum viverra rutrum nulla, id gravida dui lacinia et. Quisque mattis turpis sit amet varius rhoncus. Aliquam id mi id metus lobortis dignissim. Aenean in elementum ante. Nulla lacinia purus a arcu auctor feugiat. Nulla lacinia lorem at dolor luctus, at iaculis sapien maximus. Vivamus vel purus non orci tempor commodo. Praesent tristique eros vel mi bibendum varius. Vivamus placerat, diam ut porttitor sagittis, est mauris ornare mi, non ultricies nisl odio non justo. Nulla sollicitudin turpis ut nibh sagittis eleifend. Nunc rutrum diam vel tellus congue tempor.\n"
                + "\n"
                + "Praesent egestas magna vitae sem dapibus pretium. Donec vel pretium erat, nec maximus ante. Donec dictum fringilla ex, ut iaculis velit pharetra tristique. Cras rhoncus, dolor vitae aliquet porta, magna nisi vulputate ipsum, eu consectetur mauris orci sodales dui. In maximus sagittis rutrum. Nunc vulputate sapien quis nisi sodales, vitae lobortis enim molestie. Morbi eget finibus dolor. Sed lectus ligula, lacinia sit amet ullamcorper eget, efficitur sed mauris. Pellentesque congue finibus tellus, vel maximus est vehicula a. Aliquam eget rutrum dui. Phasellus porttitor fermentum ligula blandit dapibus. Praesent tristique facilisis vehicula. Nulla ut dictum sem, sed luctus est. Phasellus lacinia condimentum urna at gravida. Suspendisse potenti. Vestibulum scelerisque porttitor feugiat.\n"
                + "\n"
                + "Nunc feugiat pharetra ex at congue. Etiam eget velit libero. Mauris scelerisque et nisi et lobortis. Phasellus hendrerit tortor non tristique volutpat. Pellentesque non nibh id lorem suscipit sagittis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis vitae consectetur neque.\n"
                + "\n"
                + "Maecenas dui nisl, mattis eget mattis quis, suscipit ac risus. Donec dictum ligula in libero porta pulvinar. Sed consequat erat quis lacus bibendum consequat. Nam interdum, ante sed condimentum dignissim, erat urna imperdiet magna, at ornare elit nisl ut sapien. Proin sed arcu suscipit, mollis nisl eget, elementum diam. Donec bibendum, elit eu lacinia dignissim, mauris turpis convallis eros, sit amet tempor nisl tortor ac sem. In hac habitasse platea dictumst. Aenean eget ultricies mauris. Maecenas nec hendrerit nisi. Duis sed posuere eros, in bibendum odio. Proin id vulputate diam, vitae fermentum turpis. Etiam vel urna at elit ullamcorper suscipit id ac risus. ";
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("longString.txt");
            byte[] b = str.getBytes();
            fos.write(b);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if (fos != null) fos.close();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        //Deflate file -> vidu.data
        FileInputStream fis = null;
        DeflaterInputStream dis = null;
        fos = null;
        try {
            fis = new FileInputStream("longString.txt");
            dis = new DeflaterInputStream(fis);
            fos = new FileOutputStream("vidu.data");
            int code;
            while ((code = dis.read()) != -1){
                fos.write(code);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (dis != null) {
                try {
                    dis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        //Inflate file -> vidu.data
        fis = null;
        InflaterOutputStream ios = null;
        fos = null;
        try {
            fis = new FileInputStream("vidu.data");
            fos = new FileOutputStream("extract_vidu.txt");
            ios = new InflaterOutputStream(fos);
            int code;
            while ((code = fis.read()) != -1){
                ios.write(code);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (ios != null) {
                try {
                    dis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package file;

import java.io.File;
import java.nio.file.Path;
import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class listFile {

    public static void main(String[] args) {
        String folderName;
        Scanner inp = new Scanner(System.in);
        System.out.println("Nhap vao ten folder");
        folderName = inp.nextLine();
        File folder = new File(folderName);
        if (!folder.exists() || !folder.isDirectory()) {
            System.out.println("Folder does not exist");
            return;
        }
        
        File[] listFiles = folder.listFiles();
        for (File f : listFiles) {
            if (f.isFile()) System.out.println(f.getAbsolutePath());
        }
    }
}


avatar
Hoàng Quang Huy [C1907L]
2020-05-03 03:21:29




package lesson4;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;

public class DeflaterFile {

    public static void main(String[] args) {
        FileInputStream fis = null;
        DeflaterInputStream dis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D://C1907L//data.txt");
            dis = new DeflaterInputStream(fis);

            fos = new FileOutputStream("D://data.zip");

            int code;
            while ((code = dis.read()) != -1) {
                fos.write(code);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (fis != null) {
                try {
                    fis.close();

                } catch (IOException ex) {
                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            if (dis != null) {
                try {
                    dis.close();

                } catch (IOException ex) {
                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            if (fos != null) {
                try {
                    fos.close();

                } catch (IOException ex) {
                    Logger.getLogger(DeflaterFile.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}
---------------------------------------------------------------------------
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson4;

import java.io.File;

/**
 *
 * @author T480s
 */
public class ListFile {

    public static void main(String[] args) {
        File folder = new File("D://");
        readFile(folder);
    }

    public static void readFile(File file) {
        if (file.isFile()) {
            if (file.canRead()) {
                System.out.println(file.getAbsolutePath());
            }
        } else {
            System.out.println("Folder: "+file.getAbsolutePath());
            File[] lists = file.listFiles();
            for (File f : lists) {
                ListFile.readFile(f);
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            
        }
    }
}


avatar
Ngô Quang Huy [C1907L]
2020-04-29 14:41:37



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April29ZipFile;

import java.io.File;

/**
 *
 * @author Administrator
 */
public class GetFileName {
    public static void main(String[] args) {
        File folder = new File("C:\\Users\\Administrator\\Documents\\NetBeansProjects\\AptechJavaAdvanced");
        File[] listOfFiles = folder.listFiles();

        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
              System.out.println("- File: " + listOfFiles[i].getName());
            } else if (listOfFiles[i].isDirectory()) {
              System.out.println("- Directory: " + listOfFiles[i].getName());
            }
        }
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April29ZipFile;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.InflaterInputStream;

/**
 *
 * @author Administrator
 */
public class Inflater {
    public static void main(String[] args) {
        FileInputStream fis = null;
        InflaterInputStream iis = null;
        FileOutputStream fos = null;
        
        try {
            fis = new FileInputStream("vidu.data");
            iis = new InflaterInputStream(fis);
            fos = new FileOutputStream("output1.txt");
            
            int code;
            while((code=iis.read())!=-1){
                fos.write(code);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if( fis != null){
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if( iis != null){
                try {
                    iis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if( fos != null){
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package April29ZipFile;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;

/**
 *
 * @author Administrator
 */
public class Deflater {
    public static void main(String[] args) {
        FileInputStream fis = null;
        DeflaterInputStream dis = null;
        FileOutputStream fos = null;
        
        try {
            fis = new FileInputStream("data.txt");
            dis = new DeflaterInputStream(fis);
            fos = new FileOutputStream("vidu.data");
            
            int code;
            while((code=dis.read())!=-1){
                fos.write(code);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if( fis != null){
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if( dis != null){
                try {
                    dis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if( fos != null){
                try {
                    fos.close();
                } catch (IOException ex) {
                    Logger.getLogger(Deflater.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}


avatar
Nguyễn Hoàng Anh [C1907L]
2020-04-29 14:28:26



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BaiTapApril29;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.DeflaterInputStream;
import java.util.zip.InflaterInputStream;

/**
 *
 * @author Redmibook 14
 */
public class NenFileGiaiNenFIleLietKeFile {

    public static void main(String[] args) {

        FileInputStream fis = null;
        DeflaterInputStream dis = null;
        FileOutputStream fos = null;
        InflaterInputStream iis = null;
        try {

            fis = new FileInputStream("vidu2.txt");
            dis = new DeflaterInputStream(fis);
            fos = new FileOutputStream("vidu2.zip");

            int codeByte;
            while ((codeByte = dis.read()) != -1) {
                fos.write(codeByte);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (fos != null) {
            try {
                fos.close();
            } catch (IOException ex) {
                Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        try {
            fis = new FileInputStream("vidu2.zip");
            iis = new InflaterInputStream(fis);
            int c;
            StringBuilder str = new StringBuilder();
            while ((c = iis.read()) != -1) {
                str.append((char) c);
            }
            System.out.println(str);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (iis != null) {
            try {
                iis.close();
            } catch (IOException ex) {
                Logger.getLogger(NenFileGiaiNenFIleLietKeFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        File fileOrDir = new File("C:\\Users\\Redmibook 14\\Documents\\NetBeansProjects\\FileIn&De_flater");
        traverseDepthFiles(fileOrDir);
    }
    public static void traverseDepthFiles(File fileOrDir) {
        if (fileOrDir.isDirectory()) {
            File[] childFile = fileOrDir.listFiles();
            for (File value : childFile) {
                if (value.isDirectory()) {
                    traverseDepthFiles(value);
                } else {
                    System.out.println(value);
                }

            }
        }
    }
}