Java File IO學習筆記

来源:https://www.cnblogs.com/xiaonihao444/archive/2018/04/09/8763226.html
-Advertisement-
Play Games

聲明:以下轉載自:Java中的File文件類詳解 文件操作在Java的io操作中占有十分重要的地位,本文從以下幾個方面來接受Java中對文件的操作。 1.Java中新建或者刪除一個文件,文件夾以及createNewFile(),delete(),mkdir(),mkdirs()函數的使用。 2. 判 ...


聲明:以下轉載自:Java中的File文件類詳解

文件操作在Java的io操作中占有十分重要的地位,本文從以下幾個方面來接受Java中對文件的操作。
1.Java中新建或者刪除一個文件,文件夾以及createNewFile(),delete(),mkdir(),mkdirs()函數的使用。
2. 判斷文件的函數:exists(),isFile(),isAbsolute(),isDirectory(),canRead(),canWrite(),isHidden()函數的使用。
3. 文件屬性的函數:lastModified(),length(),list(),listFiles(),renameTo(),getName(),getParent(),getPath(),getAbsolutePath(),delete()函數的使用。
4. 文件輸入輸出操作中的FileInputStream(),InputStreamReader()的使用和差別。
一:創建一個文件或者文件夾:

 


public class FileTest {
    public static void main(String[] args) throws IOException {
        File file = new File("D:/hust/file.txt");
        File directory = new File("D:/hust/hk");
        File dir = new File("D:/hank/hu/file.txt");
        if (!directory.exists()) {
            System.out.println(directory.mkdir());
        }
        if (!dir.exists()) {
            System.out.println(dir.mkdirs());
        }
        if (!file.exists()) {
            System.out.println(":" + file.createNewFile());
        }
    }
}

 

上面介紹了創建文件,以及創建文件夾的兩種方式。首先是創建文件:
在D盤的hust的目錄下麵新建一個file.txt文件,通過exist()來判斷文件是否已經存在,如果文件不存在調用createNewFile(),CreateNewFile()返回一個Boolean值,如果指定的文件不存在併成功地創建,則返回 true;如果指定的文件已經存在,則返回 false。
創建文件夾如果指定的文件夾不存在可以通過mkdir(),mkdirs()來創建文件夾。
mkdir(),和mkdirs()都返回一個Boolean值,如果指定文件夾不存在並且通過mkdir()或者mkdirs()創建成功則返回一個true 值否則返回false。
mkdir(),和mkdirs()的區別是如果新建的文件目錄的上級目錄不存在則mkdir()回報異常不能成功創建文件夾,而mkdirs(),會將目錄與上級目錄一起創建。
二:判斷文件屬性的函數:
exists()判斷文件是否存在如果不存在則返回一個true,否則返回一個false。isFile()和isDirectory()分別用於判斷是不是文件和是不是文件夾,canRead(),canWrite(),isHidden(),分別用於判斷文件是否可讀,可寫,是否隱藏。

 

public class FileTest {
    public static void main(String[] args) throws IOException {
        File file = new File("D:/hust/file.txt");
        File directory = new File("D:/hust/hk");
        File dir = new File("D:/hank/hu/file.txt");
        if (!directory.exists()) {
            System.out.println(directory.mkdir());
        }
        if (!dir.exists()) {
            System.out.println(dir.mkdirs());
        }
        if (!file.exists()) {
            System.out.println(":" + file.createNewFile());
        }
        file.setReadable(true);
        file.setWritable(false);
        System.out.println("isFile:"+file.isFile()+"\tisDirectory:"+file.isDirectory()+"\tcanRead:"+file.canRead()+"\tcanWrite:"+file.canWrite());
        System.out.println(dir.isFile()+":"+dir.isDirectory());
    }
}

 

輸出結果如下:
isFile:true isDirectory:false
canRead:true canWrite:false
isFile:false isDirectory:true
三:文件屬性的函數
:lastModified(),length(),list(),listFiles(),renameTo(),getName(),getParent(),getPath(),getAbsolutePath()函數的使用。

 

public class FileTest {
    public static void main(String[] args) throws IOException {
        File dir = new File("D:/hust");
        String[] str=dir.list();
        File[] str1=dir.listFiles();
        System.out.println("lastModified():"+new Date(dir.lastModified()));
        System.out.println("length():"+dir.length()+"\ngetAbsolutePath:"+dir.getAbsolutePath());
        System.out.println("getPath:"+dir.getPath());
        System.out.println("getName:"+dir.getName()+"\ngetParent:"+dir.getParent());
        for(int j=0;j<str1.length;j++)
            System.out.println(":"+str1[j]);
        for(int i=0;i<str.length;i++)
        {
            System.out.println(":"+str[i]);
        }
    }
}

 

輸出結果:
lastModified():Mon Aug 01 22:01:15 CST 2016
length():0
getAbsolutePath:D:\hust
getPath:D:\hust
getName:hust
getParent:D:\
:D:\hust\file.txt
:D:\hust\hank
:D:\hust\hk
:D:\hust\king
:file.txt
:hank
:hk
:king
lastModified()函數返回一個long類型的值,上面的類子中通過Date函數將long類型的值轉化為了日期。getAbsolutePath()返回目錄的絕對路徑。最重要的兩個方法是list(),和listFiles(),list()是返回目錄下麵所有的目錄或文件的名稱,返回的是一個字元串數組。而listFiles()返回的是目錄下麵的文件和目錄數組,返回的是文件和目錄的絕對路徑。
Delete()的用法,如何刪除一個文件和刪除一個文件夾。
刪除一個文件比較簡單,直接判斷文件是否存在,如果存在的話就刪除,如果文件不存在可以不用操作。但是刪除一個文件夾比較麻煩,我們不能夠直接的刪除一個文件夾,刪除文件夾時必須保證該文件夾為空,也就是說文件夾裡面的文件和文件夾要全部被刪除之後才能夠刪除該文件夾。下麵是實例:

 

public class FileTest {
    public static void main(String[] args) throws IOException {
        deleteFiles("D:/Xiaomi");
    }
    public static void deleteFiles(String path) {
        File file = new File(path);
        if (!file.exists()) {
            return;
        }
        if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File myfile : files) {
                System.out.println(":" + myfile.getAbsolutePath());
                deleteFiles(myfile.getAbsolutePath());
            }
            file.delete();
        }
    }
}

 

上面的D:/xiaomi是一個文件夾,它的下麵還有其他的文件夾與文件,如果直接調用delete()函數的話,是刪除不了的。因此利用遞歸的演算法先刪除其裡面的文件和文件夾,在刪除D:/xiaomi就可以了。
四:文件輸入輸出操作中的FileInputStream(),InputStreamReader()的使用和差別。
FileInputStream ()是使用位元組方式輸入,InputStreamReader()字元方式輸入。一般位元組方式輸入用來處理圖片,聲音,圖像等二進位流。

 

public class FileTest {
    public static void main(String[] args) throws IOException {
        // deleteFiles("D:/Xiaomi");
        System.out.println(":" + ReadFileByByte("D:/File1/心理健康常識.txt"));
        System.out.println(":" + ReadFileByChar("D:/File1/心理健康常識.txt"));
    }

    public static String ReadFileByByte(String filepath)
            throws FileNotFoundException {
        File file = new File(filepath);
        StringBuffer sb = new StringBuffer();
        if (!file.exists() || !file.isFile()) {
            System.out.println("this file is not exist!");
            return null;
        }
        FileInputStream fileinputstream = new FileInputStream(file);
        byte[] temp = new byte[1024];
        try {
            while (fileinputstream.read(temp) != -1) {
                sb.append(new String(temp));

            }
            fileinputstream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // System.out.println(":"+sb.length());
        return sb.toString();
    }

    public static String ReadFileByChar(String filepath) {
        File file = new File(filepath);
        if (!file.exists() || !file.isFile()) {
            return null;
        }

        StringBuffer content = new StringBuffer();

        try {
            char[] temp = new char[1024];
            FileInputStream fileInputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(
                    fileInputStream);
            while (inputStreamReader.read(temp) != -1) {
                content.append(new String(temp));
                temp = new char[1024];
            }

            fileInputStream.close();
            inputStreamReader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content.toString();
    }

別。

聲明:以下轉載自: Java File類總結和FileUtils類

文件存在和類型判斷

  創建出File類的對象並不代表該路徑下有此文件或目錄。

  用public boolean exists()可以判斷文件是否存在。

  File類的對象可以是目錄或者文件。

  如果是目錄,public boolean isDirectory()返回true;

  如果是文件(非目錄則是文件),public boolean isFile()返回true;

  但是註意需要先判斷文件是否存在,如果文件不存在,上面兩個方法都返回false,即不存在的File類對象既不是文件也不是目錄

 

創建文件

  public boolean createNewFile()會創建一個新的空文件,只有該文件不存在的時候會創建,如果文件已經存在的話則返回false。

創建文件夾

  public boolean mkdir()

  創建目錄,成功返回true。只能創建一個文件夾,要求所有的父目錄都存在,否則創建失敗。

  public boolean mkdirs()

  創建目錄,成功返回true,會創建所有不存在的父目錄。(註意即便最後創建失敗,但是也可能創建了一些中間目錄)。

  上面兩個方法如果要創建的目錄已經存在,不再重新創建,都返回false,只有新建目錄返回true。

 

目錄操作

  列出目錄中的文件有以下方法可選:

  String[] list()

  String[] list(FilenameFilter filter)

  返迴文件名數組。

  File[] listFiles()

  File[] listFiles(FileFilter filter)

  File[] listFiles(FilenameFilter filter)

  返回File數組。

 

  參數是文件或者文件名過濾器。

 

  註意返回為空和返回為null的意義是不同的。

  若不包含(符合條件的)文件,返回為空。

  但是如果返回為null,則表明調用方法的File對象可能不是一個目錄,或者發生了IO錯誤。

 

刪除文件

  boolean delete()方法會刪除文件,如果File對象是文件則直接刪除,對於目錄來說,如果是空目錄則直接刪除,非空目錄則無法刪除,返回false。

  如果要刪除的文件不能被刪除則會拋出IOException。

 

  註意:不論是創建文件、創建目錄還是刪除文件,只有在動作真正發生的時候會返回true。

 

FileUtils類

  在項目中寫一些工具類包裝通用操作是很有必要的,看了一下apache的FileUtils類,copy了一些方法出來:

複製代碼
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mengdd.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
 * FileUtils copied from org.apache.commons.io.FileUtils
 */
public class FileUtils {
    /**
     * Construct a file from the set of name elements.
     *
     * @param directory
     *            the parent directory
     * @param names
     *            the name elements
     * @return the file
     */
    public static File getFile(File directory, String... names) {
        if (directory == null) {
            throw new NullPointerException(
                    "directorydirectory must not be null");
        }
        if (names == null) {
            throw new NullPointerException("names must not be null");
        }
        File file = directory;
        for (String name : names) {
            file = new File(file, name);
        }
        return file;
    }

    /**
     * Construct a file from the set of name elements.
     *
     * @param names
     *            the name elements
     * @return the file
     */
    public static File getFile(String... names) {
        if (names == null) {
            throw new NullPointerException("names must not be null");
        }
        File file = null;
        for (String name : names) {
            if (file == null) {
                file = new File(name);
            }
            else {
                file = new File(file, name);
            }
        }
        return file;
    }

    /**
     * Opens a {@link FileInputStream} for the specified file, providing better
     * error messages than simply calling <code>new FileInputStream(file)</code>
     * .
     * <p>
     * At the end of the method either the stream will be successfully opened,
     * or an exception will have been thrown.
     * <p>
     * An exception is thrown if the file does not exist. An exception is thrown
     * if the file object exists but is a directory. An exception is thrown if
     * the file exists but cannot be read.
     *
     * @param file
     *            the file to open for input, must not be {@code null}
     * @return a new {@link FileInputStream} for the specified file
     * @throws FileNotFoundException
     *             if the file does not exist
     * @throws IOException
     *             if the file object is a directory
     * @throws IOException
     *             if the file cannot be read
     */
    public static FileInputStream openInputStream(File file) throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                throw new IOException("File '" + file
                        + "' exists but is a directory");
            }
            if (file.canRead() == false) {
                throw new IOException("File '" + file + "' cannot be read");
            }
        }
        else {
            throw new FileNotFoundException("File '" + file
                    + "' does not exist");
        }
        return new FileInputStream(file);
    }

    /**
     * Opens a {@link FileOutputStream} for the specified file, checking and
     * creating the parent directory if it does not exist.
     * <p>
     * At the end of the method either the stream will be successfully opened,
     * or an exception will have been thrown.
     * <p>
     * The parent directory will be created if it does not exist. The file will
     * be created if it does not exist. An exception is thrown if the file
     * object exists but is a directory. An exception is thrown if the file
     * exists but cannot be written to. An exception is thrown if the parent
     * directory cannot be created.
     *
     * @param file
     *            the file to open for output, must not be {@code null}
     * @param append
     *            if {@code true}, then bytes will be added to the
     *            end of the file rather than overwriting
     * @return a new {@link FileOutputStream} for the specified file
     * @throws IOException
     *             if the file object is a directory
     * @throws IOException
     *             if the file cannot be written to
     * @throws IOException
     *             if a parent directory needs creating but that fails
     */
    public static FileOutputStream openOutputStream(File file, boolean append)
            throws IOException {
        if (file.exists()) {
            if (file.isDirectory()) {
                throw new IOException("File '" + file
                        + "' exists but is a directory");
            }
            if (file.canWrite() == false) {
                throw new IOException("File '" + file
                        + "' cannot be written to");
            }
        }
        else {
            File parent = file.getParentFile();
            if (parent != null) {
                if (!parent.mkdirs() && !parent.isDirectory()) {
                    throw new IOException("Directory '" + parent
                            + "' could not be created");
                }
            }
        }
        return new FileOutputStream(file, append);
    }

    public static FileOutputStream openOutputStream(File file)
            throws IOException {
        return openOutputStream(file, false);
    }

    /**
     * Cleans a directory without deleting it.
     *
     * @param directory
     *            directory to clean
     * @throws IOException
     *             in case cleaning is unsuccessful
     */
    public static void cleanDirectory(File directory) throws IOException {
        if (!directory.exists()) {
            String message = directory + " does not exist";
            throw new IllegalArgumentException(message);
        }

        if (!directory.isDirectory()) {
            String message = directory + " is not a directory";
            throw new IllegalArgumentException(message);
        }

        File[] files = directory.listFiles();
        if (files == null) { // null if security restricted
            throw new IOException("Failed to list contents of " + directory);
        }

        IOException exception = null;
        for (File file : files) {
            try {
                forceDelete(file);
            }
            catch (IOException ioe) {
                exception = ioe;
            }
        }

        if (null != exception) {
            throw exception;
        }
    }

    // -----------------------------------------------------------------------
    /**
     * Deletes a directory recursively.
     *
     * @param directory
     *            directory to delete
     * @throws IOException
     *             in case deletion is unsuccessful
     */
    public static void deleteDirectory(File directory) throws IOException {
        if (!directory.exists()) {
            return;
        }

        cleanDirectory(directory);

        if (!directory.delete()) {
            String message = "Unable to delete directory " + directory + ".";
            throw new IOException(message);
        }
    }

    /**
     * Deletes a file. If file is a directory, delete it and all
     * sub-directories.
     * <p>
     * The difference between File.delete() and this method are:
     * <ul>
     * <li>A directory to be deleted does not have to be empty.</li>
     * <li>You get exceptions when a file or directory cannot be deleted.
     * (java.io.File methods returns a boolean)</li>
     * </ul>
     *
     * @param file
     *            file or directory to delete, must not be {@code null}
     * @throws NullPointerException
     *             if the directory is {@code null}
     * @throws FileNotFoundException
     *             if the file was not found
     * @throws IOException
     *             in case deletion is unsuccessful
     */
    public static void forceDelete(File file) throws IOException {
        if (file.isDirectory()) {
            deleteDirectory(file);
        }
        else {
            boolean filePresent = file.exists();
            if (!file.delete()) {
                if (!filePresent) {
                    throw new FileNotFoundException("File does not exist: "
                            + file);
                }
                String message = "Unable to delete file: " + file;
                throw new IOException(message);
            }
        }
    }

    /**
     * Deletes a file, never throwing an exception. If file is a directory,
     * delete it and all sub-directories.
     * <p>
     * The difference between File.delete() and this method are:
     * <ul>
     * <li>A directory to be deleted does not have to be empty.</li>
     * <li>No exceptions are thrown when a file or directory cannot be deleted.</li>
     * </ul>
     *
     * @param file
     *            file or directory to delete, can be {@code null}
     * @return {@code true} if the file or directory was deleted, otherwise
     *         {@code false}
     *
     */
    public static boolean deleteQuietly(File file) {
        if (file == null) {
            return false;
        }
        try {
            if (file.isDirectory()) {
                cleanDirectory(file);
            }
        }
        catch (Exception ignored) {
        }

        try {
            return file.delete();
        }
        catch (Exception ignored) {
            return false;
        }
    }

    /**
     * Makes a directory, including any necessary but nonexistent parent
     * directories. If a file already exists with specified name but it is
     * not a directory then an IOException is thrown.
     * If the directory cannot be created (or does not already exist)
     * then an IOException is thrown.
     *
     * @param directory
     *            directory to create, must not be {@code null}
     * @throws NullPointerException
     *             if the directory is {@code null}
     * @throws IOException
     *             if the directory cannot be created or the file already exists
     *             but is not a directory
     */
    public static void forceMkdir(File directory) throws IOException {
        if (directory.exists()) {
            if (!directory.isDirectory()) {
                String message = "File " + directory + " exists and is "
                        + "not a directory. Unable to create directory.";
                throw new IOException(message);
            }
        }
        else {
            if (!directory.mkdirs()) {
                // Double-check that some other thread or process hasn't made
                // the directory in the background
                if (!directory.isDirectory()) {
                    String message = "Unable to create directory " + directory;
                    throw new IOException(message);
                }
            }
        }
    }

    /**
     * Returns the size of the specified file or directory. If the provided
     * {@link File} is a regular file, then the file's length is returned.
     * If the argument is a directory, then the size of the directory is
     * calculated recursively. If a directory or subdirectory is security
     * restricted, its size will not be included.
     *
     * @param file
     *            the regular file or directory to return the size
     *            of (must not be {@code null}).
     *
     * @return the length of the file, or recursive size of the directory,
     *         provided (in bytes).
     *
     * @throws NullPointerException
     *             if the file is {@code null}
     * @throws IllegalArgumentException
     *             if the file does not exist.
     *
     */
    public static long sizeOf(File file) {

        if (!file.exists()) {
            String message = file + " does not exist";
            throw new IllegalArgumentException(message);
        }

        if (file.isDirectory()) {
            return sizeOfDirectory(file);
        }
        else {
            return file.length();
        }

    }

    /**
     * Counts the size of a directory recursively (sum of the length of all
     * files).
     *
     * @param directory
     *            directory to inspect, must not be {@code null}
     * @return size of directory in bytes, 0 if directory is security
     *         restricted, a negative number when the real total
     *         is greater than {@link Long#MAX_VALUE}.
     * @throws NullPointerException
     *             if the directory is {@code null}
     */
    public static long sizeOfDirectory(File directory) {
        checkDirectory(directory);

        final File[] files = directory.listFiles();
        if (files == null) { // null if security restricted
            return 0L;
        }
        long size = 0;

        for (final File file : files) {

            size += sizeOf(file);
            if (size < 0) {
                break;

            }

        }

        return size;
    }

    /**
     * Checks that the given {@code File} exists and is a directory.
     *
     * @param directory
     *            The {@code File} to check.
     * @throws IllegalArgumentException
     *             if the given {@code File} does not exist or is not a
     *             directory.
     */
    private static void checkDirectory(File directory) {
        if (!directory.exists()) {
            throw new IllegalArgumentException(directory + " does not exist");
        }
        if (!directory.isDirectory()) {
            throw new IllegalArgumentException(directory
                    + " is not a directory");
        }
    }

}
複製代碼

 

 

參考資料

  File類官方文檔:

  http://docs.oracle.com/javase/7/docs/api/java/io/File.html

  org.apache.commons.io.FileUtils源碼:

  http://grepcode.com/file/repo1.maven.org/maven2/commons-io/commons-io/2.4/org/apache/commons/io/FileUtils.java

 

  本博客舊博文:

  Java IO File類

  Java IO 用遞歸實現目錄刪除和樹形目錄展示 Java實現


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • python自己也自學過一段時間了,看過視頻,也買過幾本基礎的書來看,目前為止對於一些簡單的代碼還是可以看懂,但是自己總是覺得缺少些什麼,可能是缺少系統化的學習,也可能是缺少實際項目經驗,對於這些缺少的感覺,大概原因就是自己沒有堅持,總是斷斷續續的學習,一方面有工作上的原因,另一方面也有自身的原因. ...
  • Pyhton中字元串的格式化輸出在前面已經總結了,接下來介紹一些常用的字元串操作 先定義一個字元變數,以下的操作都以此為例: 1.首字母大寫(整個字元串的首字母) 2.將所有字母變大寫或變小寫 輸出結果分別為: my name is china MY NAME IS CHINA 3.首字母大寫(每個 ...
  • 好吧,廢話不多說,鄙人造輪子了。 如題所示,生成自定義模板的資料庫三件套 javabean/javaclient/sqlMap 使用到Lombok、freemarker 上述是讀取資料庫的表信息跟欄位信息,接下來是表名跟欄位名的命名轉換規則介面 再然後就是資料庫拿表跟欄位信息了 代碼中有註釋信息,相 ...
  • Servlet 的致命的兩個缺點(面試題): ActionServlet的實現步驟: 1、創建Action介面 : 2、創建一個Action 重寫Action介面的處理方法: 3、創建ActionFilter過濾器(實現Filter介面 重寫 Filter生命周期的方法): 解析URI的getAct ...
  • 閱讀目錄 一般形式 不含參數列表 含參數列表 閱讀目錄 閱讀目錄 一般形式 不含參數列表 含參數列表 一般形式 不含參數列表 含參數列表 一、一般形式 this 有兩種形式: 1)不含參數列表,例如:this.age , this.speak() , this 等等 2)含參數列表,例如:this( ...
  • leetcode,編程題,二叉樹,中序遍歷,非遞歸實現,迭代實現 ...
  • 配置指令 (。。。) 錯誤日誌 (。。。) 異常處理 為什麼異常處理很方便 (。。。) PHP的異常處理實現 (。。。) SPL異常 (。。。) ...
  • 多態是C++的三大法器之一,此處我們用C模擬多態,加深對C++的多態的理解 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...