search
Home类库下载java类库Filtering, reading and writing of JAVA I/O files

一、文件的过滤

public class guolv implements FilenameFilter
{
    public static void main(String[] args)
    {
        File file = new File("F:\\java\\workspace\\Fanshe");//找到文件路径
        String[] files = file.list(new guolv());//把稳建议数组的方式打开
        System.out.println(files[0] + "===");
        
    }
    //返回值为true则说明文件符合要求求
    //返回值为false则说明文件不符合要求
    @Override
    public boolean accept(File dir, String name)
    {
        if(name.endsWith(".classpath"))
        {
            return true;
        }else
        {
            return false;
        }
    }
}

 二、文件的读取

public class readers
{
    public static void main(String[] args) throws Exception
    {
        File file = new File("F:\\java\\workspace\\Fanshe\\src\\com\\cyg\\fanshe.java");//读取文件
        FileInputStream fi = new FileInputStream(file);//创建字节流,打开该 文件
        byte[] b = new byte[fi.available()];//fi.available 可以获取文件占多少字节
        int a = -1;
        while((a= fi.read(b))!= -1)//判断文件是否到达文件末尾
        {
            //System.out.println(new String(b));
        }
        System.out.println(new String(b));
        //关闭流
        fi.close();
        
    }
}


三、文件的写入

public class output
{
    public static void main(String[] args) throws Exception
    {
        File file = new File("F:\\a.txt");
        FileOutputStream out = new FileOutputStream(file);
        out.write("abmin".getBytes());
        out.flush();//清楚缓存
        out.close();//关闭流
    }    
}


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools