java foundation day 18 File and recursive notes

  1. IO: (Input Output) input and output stream
    from the memory to the hard disk is the output stream Output
    from the hard disk to the memory Input is the input stream

    The most basic is the file File IO operations

  2. File

    1. The concept: that java in a file or folder. If there is no suffix represents a folder, if it means the file suffix.
    2. Effect: the basis for providing the operation flow IO
    3. use:
      1. Constants:
        . 1.1 static String pathSeparator
        system-dependent path separator character, for convenience, is represented as a string.
        1.2. Static String separator

      2. Constructors:
        2.1 File (String pathname) Creates a File object based on the file name,
        pathname :( suffix if there is a file object, if no suffix will default to a folder object)
        1. relative path: relative to the current Java classes project
        2. absolute path: start from the root directory or drive letter / have said from the root directory or drive letter

        2.2 File (String parent, String child ) is created in the parent directory of a file or folder
        parent: parent directory
        child: the current directory or the current file

        2.3 File (File parent, String child) Creates a file in the parent directory or folder

      3. Common methods:
        Common methods: obtaining sub-folder or subfolder method

      • 1.String [] list () to get the current folder and all subfolders or subfolder name // file is not under a
        2.File [] listFiles () to get the current folder and all subfolders or child file object

        =There are filtering=
        3.String [] List (the FilenameFilter filter)
        acquires the file name of a filename filtering
        FilenameFilter: filename filter interfaces
        4.File [] listFiles (FilenameFilter filter)
        obtained according to the file name of the file object filtering
        FilenameFilter: filename filter Interface

        ----------------------------- above only for filtering the file name or the folder according to the following other properties may be filtered through a file , for example: file size -----------------------------
        5.File [] the listFiles (the FileFilter filter)
        obtained according to the file after filtering file object
        FileFilter: filter Interface file

  3. Recursion:

    1. Concept: an idea, it is an algorithm. Call your own methods in internal methods. (Do their own)

    2. Action: is a similar simplified business logic (cyclic) code.

    3. Use patterns, features:

      1. By way into value, lookup logic rule: a write all known conditions
        is similar arithmetic logic code
      2. Judging by the condition (Condition / cycle) manner, when the condition of its method invocation law.
        If not it will not own way, which is exported
    4. scenes to be used:

      1. Tree structure data, menu structure, reporting relationships and other data query
      2. Logical operation similar structure
      3. Suitable for less hierarchy, a small amount of data of the scene. (Most importantly) if the multi-level, and the large amount of data circulating.
    5. Which problems:
      (1) define the data is recursively defined. (Fibonacci function: Feibolaqi number of columns)
      (2) Solutions to implement a recursive algorithm. (Tower of Hanoi)
      this kind of problem in itself though no obvious recursive structure, but with a recursive solution is simpler than an iterative solution, such as Hanoi problem.
      Structure (3) the data is recursively defined.
      The binary tree, the generalized table, etc., due to the inherent structure of the recursive nature, their operation can be described recursively.

    6. Precautions:

      1. There must be recursive exports
      2. Can be used with a circulation loop, do not use recursion, because the efficiency is extremely low.
        Why inefficient?
        Call the method is to create a new stack frame, stack, and stack level is limited
        StackOverflowError: stack memory overflow error.
Published 14 original articles · won praise 1 · views 243

Guess you like

Origin blog.csdn.net/weixin_45061669/article/details/104829888