Program file reading method and device, computer equipment and readable storage medium
Through the templated program file reading method, the public logic is encapsulated as a template, and the difference logic is customized by the user, solving the problem of frequent reading errors in the existing technology, and achieving efficient and accurate file reading.
Patent Information
- Application Number
- CN202510352514.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, program file reading methods are poor in universality and compatibility, resulting in frequent reading errors and increasing development and maintenance costs.
The templated method is used to split the program file reading process into a public reading template and a context-making template. The public part is encapsulated as a template, and the difference part is customized by the user, including parameters such as file address, separator and object type.
It improves the accuracy and efficiency of program file reading, especially suitable for batch file processing, reduces the amount of code and test workload, and improves development efficiency.
Smart Images

Figure CN120295665A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data processing, and particularly to a method, apparatus, computer device, and readable storage medium for reading program files. Background Art
[0002] A program file refers to a file in a specific format that stores computer-executable instructions or source code and is used to implement a certain function or task. In many scenarios, it is necessary to read program files. For example, in software development and debugging, developers usually need to read source code files from a server or a code community for editing, compiling, or debugging. Another example is in data processing and analysis, where it is necessary to read scripts or configuration files containing data processing logic. There are also automated execution of scripts, as well as game and multimedia development, all of which require obtaining program files.
[0003] The types of program file formats are numerous and complex. Developers need to implement parsing logic separately for each format, and sometimes for files of the same format, it is also necessary to write a set of scripts according to the business of the file to be read. This not only increases the code volume, but also has a large maintenance cost and increases the test workload and the risk of potential problems.
[0004] In the prior art, there are also technical studies on using models for file reading, but these methods are usually less general and compatible, and when there are differences in files, it is easy to have situations of reading errors. Summary of the Invention
[0005] To solve the above problems, embodiments of the present application provide a method, apparatus, computer device, and readable storage medium for reading program files to overcome or at least partially overcome the deficiencies of the prior art.
[0006] The present application adopts the following technical solutions:
[0007] In a first aspect, the present application provides a method for reading program files, including:
[0008] Displaying a context-defined template for filling, where the context-defined template includes the following fields: file address, file line separator, and file line object type;
[0009] Reading a common reading template, where the common reading template includes the following abstract methods: preprocessing method, file line reading method, postprocessing method, exception handling method, and end processing method;
[0010] Reading a file according to the content of the context-defined template and the common reading template.
[0011] In a second aspect, the present application further provides a device for reading program files, where the device includes:
[0012] A customized parameter acquisition unit for displaying a context - customized template for filling, where the context - customized template includes the following fields: file address, file line delimiter, and file line object type;
[0013] A common template reading unit for reading a common reading template, where the common reading template includes the following abstract methods: pre - processing method, file line reading method, post - processing method, exception handling method, and end - processing method;
[0014] A file reading unit for reading a file according to the content of the context - customized template and the common reading template.
[0015] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above - mentioned program file reading method are implemented.
[0016] In a fifth aspect, a computer - readable storage medium is provided. The computer - readable storage medium stores a computer program. When the computer program is instructed by a processor, the steps of the above - mentioned program file reading method are implemented.
[0017] The above - mentioned at least one technical solution adopted in the embodiments of the present application can achieve the following beneficial effects:
[0018] For program files, the present application provides a reading method based on templates. In the present application, common parts such as downloading files, parsing file lines, and converting formats are encapsulated to form a common reading template, and the remaining parts with non - general logic are abstracted to form a context - customized template. The context - customized template allows users to specify parameters to implement differential logic; finally, a file is read according to the content of the context - customized template and the common reading template. The present application splits the reading template of program files into a common part and a customized part, encapsulates the complex common processing process and abstracts the differences, not only supports user self - expansion, but also has a clear code structure; moreover, the present application can better be compatible with differential logic, improve reading accuracy, especially suitable for reading batch files, thus improving development efficiency; further, when developing business, there is no need to pay attention to the encapsulated file reading process logic outside the business, and only need to focus on the processing of business data, effectively improving the development work efficiency. When performing batch file processing, if the structural main body is the same, there is no need to review the code logic from scratch, and problems can be detected more quickly. Description of the Drawings
[0019] The accompanying drawings described herein are used to provide a further understanding of the present application and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0020] Figure 1 A flowchart showing a method for reading a program file according to an embodiment of the present application is shown;
[0021] Figure 2 A schematic diagram showing an application scenario according to an embodiment of the present application is shown;
[0022] Figure 3 A flowchart showing a method for reading a program file according to another embodiment of the present application is shown;
[0023] Figure 4 A schematic diagram showing the structure of a program file reading device according to an embodiment of the present application is shown;
[0024] Figure 5 A schematic diagram showing the structure of a computer device according to an embodiment of the present application is shown. Detailed implementation manners
[0025] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0026] In the scenarios of software development and the maintenance of online systems, it is often necessary to read program files. Currently, for the methods of reading program files, there are usually problems of poor universality and compatibility. Even when there are differences in files, errors may occur during reading.
[0027] The concept of the present application is as follows: In view of the problems that the present application needs to construct a reading script for each file or use the template method to be compatible with differences, large amounts of code, increased testing workload, and risks of potential problems when reading program files, the common logical parts are packaged based on the template pattern, such as downloading files, reading files, parsing file lines, and converting formats, etc. The remaining non-universal parts are abstracted and configured by the user himself, so as to improve the efficiency of reading program files.
[0028] Figure 1 A flowchart showing a method for reading a program file according to an embodiment of the present application is shown. From Figure 1 it can be seen that this embodiment includes steps S110 to S130:
[0029] Step S110: Display a context - defining template for filling. The context - defining template includes the following fields: file address, file line delimiter, and file line object type.
[0030] Figure 2 The figure shows a schematic diagram of an application scenario according to an embodiment of the present application. As can be seen from the figure, the program file is stored in the server, and the user downloads and further processes the program file on the terminal. The terminal can be in various forms, such as a PC, a personal mobile device, etc. In addition, a database (not shown in the figure) is connected to the terminal. The ultimate goal is to store the read program file in the database. The database can be integrated into the server or set separately relative to the server. The present application does not limit this.
[0031] The method provided by the present application is mainly applicable to program files. A program file is a carrier for storing information such as code logic, configuration parameters, and build instructions in software development. For example, a source code text is a text file containing the core logic of the program and is usually written in the syntax of a programming language. The present application is applicable to various program files, including but not limited to texts edited in languages such as Python, Java, C++. For the convenience of description below, a file with the extension.jxt is taken as an example for illustration.
[0032] .jxt is a new structured data file format that has been gradually applied in fields such as cross - platform data exchange and automated test scripts. Its text usually includes a file header (head) and a file content (body), and each line is separated by a specified delimiter, such as "|".
[0033] In the present application, the template for reading a file is encapsulated into two parts. One part is relatively personalized and not general. This part is abstracted as a context - defining template. The context is mainly used to define, but not limited to, business parameters such as the file address of a program file, the file line delimiter, and the object type corresponding to the file line.
[0034] When entering the process of reading a program file, display this context - defining template, and the user can fill in the above - mentioned parameters, and these parameters can all be customized.
[0035] For example, the file line delimiter of a.jxt file can be set to, but not limited to: "|", that is, the target program file to be read uses a vertical line to split lines.
[0036] The object type is such as:
[0037] FileModle{
[0038] @Column(index = 1, name = "Column Name 1")
[0039] private String clo1;
[0040] @Column(index = 2, name = "Column Name 2")
[0041] private String clo2;
[0042] }。
[0043] That is, the file line object type is defined as the mapping relationship between file columns and program fields.
[0044] This application does not limit the above business parameters such as file address, file line delimiter, and object type corresponding to the file line, and they can be increased, decreased, and set according to needs.
[0045] In some embodiments, default values can be set for the file line delimiter and the file line object type for different types of program files to reduce user operations. Only when the parameters set by the user are different from the default values does the user need to make manual adjustments.
[0046] Step S120, read the common reading template, and the common reading template includes the following abstract methods: pre-processing method, file line reading method, post-processing method, exception handling method, and end processing method.
[0047] Step S130, read the file according to the content of the context-based template and the common reading template.
[0048] In this application, the general logical part in the file reading process is defined as the common part and encapsulated to form a common reading template. The common part includes but is not limited to downloading files, reading files, parsing file lines and converting formats, etc. In this application, several abstract methods for implementing file reading are encapsulated in the common reading template, including but not limited to pre-processing method, file line reading method, post-processing method, exception handling method, and end processing method.
[0049] Among them, the pre-processing method is mainly used to confirm and judge the file information before reading the file; the file line reading method is mainly used to process the file content when reading the file; the post-processing method is mainly used for verifying the correctness of the file after the file is read and executing notifications, etc.; the exception handling method is mainly used for handling some abnormal problems encountered during the file reading process; the end processing method is mainly used for processing the cache after the file is read.
[0050] In some embodiments of the present application, the processing logic of the preprocessing method includes: verifying whether the target file exists according to the file address. If it does not exist, the process ends; if the target file exists, determining whether the file name of the target file conforms to a preset specification. If it does not conform, the process ends; if the file name conforms to the preset specification, downloading the target file from the server to the local.
[0051] During the preprocessing process, it is possible to verify whether the target file exists. Specifically, it is possible to search the server according to the file address to determine whether the target file indicated by the file address exists. If it does not exist, the file address may be incorrect or the target file has been deleted, and the process is directly ended. If the target file indicated by the file address exists, it is possible to determine whether the file name of the target file conforms to a preset specification, such as the extension being.jxt. If it does not conform to the preset specification, it means that the target file may not be what the user wants or the target file is incorrect, and the process is directly ended. If the file name of the target file conforms to the preset specification, the target file is downloaded from the server to the local to facilitate subsequent reading of the file content. Here, "downloading" can be in the form of caching, that is, placing the target file in the local cache; it can also be in the form of permanence, that is, placing the target file on the local hard disk. After the reading is completed, the target file can be deleted to free up space.
[0052] The target file often has the situation of resuming reading from a breakpoint. In this regard, in some embodiments of the present application, the context creation template further includes: a field indicating whether breakpoint resumption is supported, and the user can set whether to support breakpoint resumption according to needs.
[0053] In some embodiments of the present application, the processing logic of the preprocessing method further includes: before the step of downloading the target file from the server to the local, determining whether the target file is a breakpoint resumption according to the existing content in the database. If not, directly execute the step of downloading the target file from the server to the local; if it is a breakpoint resumption, determining whether breakpoint resumption is supported. If breakpoint resumption is supported, enter the processing logic of the file line reading method; if breakpoint resumption is not supported, enter the processing logic of the exception handling method.
[0054] Before pulling the target file to the local, determine whether the target file is for resume reading. For the specific determination process, the files already existing in the database can be identified. For example, if there is a stored file in the database with the same file name as the target file, and the number of lines of the stored file is greater than the set number of file header lines, it is determined as resume reading; otherwise, it is not resume reading. If the target file is not for resume reading, directly execute the step of downloading the target file from the server to the local; if the target file is for resume reading, determine whether resume reading is supported. If resume reading is supported, enter the processing logic of the file line reading method and continue reading according to the resume reading method for the breakpoint file in the file line reading method; if resume reading is not supported, this situation is regarded as an abnormal situation, and enter the processing logic of the exception handling method.
[0055] In some embodiments of the present application, the processing logic of the file line reading method includes: determining whether the current process is for resume reading. If not, read the file header content from the target file downloaded to the local according to the number of file header lines. If it is for resume reading, skip the acquisition of the file header content; read the file content lines line by line. For a file content line, determine whether the field value type of the file content line exists and meets the preset requirements. If not, end the process; if so, convert each file content line into a corresponding data object according to the file line object type; encapsulate the data objects corresponding to each file content line into a list. When the number of lines in the list reaches the preset threshold, perform batch storage of the data in the database.
[0056] After entering the file line reading method, the reading of the file body is entered. As mentioned above, the file body usually includes a file header (head) and a file content (body). The file header can be one line or multiple lines. In some embodiments of the present application, the context specification template further includes: the number of file header lines. The user can specify the number of file header lines, that is, the specified number of lines of text read from the starting position of the target file are all used as the file header.
[0057] When entering the file line reading, determine whether the current process jumps from the resume reading determined by the previous processing method. If not, read according to the preset number of file header lines from the target file downloaded to the local, and process the read specified number of lines of text as the file header. If the previous process jumps from the resume reading determined by the previous processing method, skip the acquisition of the file header content, because resume reading usually only supports the resume reading of content lines. At this time, the file header has been processed, and directly enter the reading of the file content lines, that is, continue to read the content lines according to the line number at the breakpoint.
[0058] When reading the lines of the file content, read the lines of the file content line by line. For a line of file content, determine whether the field value type of the file content line exists and meets the preset requirements. If not, end the process; if so, convert each file content line into a corresponding data object according to the file line object type; finally, encapsulate the data objects corresponding to each file content line into a list. When the number of lines in the list reaches the preset threshold, perform batch data storage in the database.
[0059] That is, read the content lines one by one. When reading, if the field value type of a line of file content does not exist or does not meet the preset requirements, such as the format requirements, it means that the file content is incorrect and directly end the process. Further, it can enter the exception handling method. If there is no problem with the field value of the file content line, convert each file content line into a corresponding data object according to the aforementioned file line object type, and encapsulate the data objects into a list. When the number of lines in the list reaches the preset threshold, such as 1000 lines, batch data storage in the database can be performed, that is, stored in the database. Then continue to read the lines of the file content until the file body is read completely.
[0060] After the file body is read, enter the post-processing stage. In some embodiments of the present application, the processing logic of the post-processing method includes: verifying whether the number of lines of the file stored in the database after storage is consistent with the target file downloaded to the local. If they are consistent, update the file batch acceptance success status and notify the file reading initiator that the file acceptance is successful; if they are inconsistent, end the process and notify the file reading initiator that the file acceptance fails.
[0061] After the file body is read, verify whether the file stored in the database after storage is consistent with the file downloaded to the local. It is mainly confirmed by verifying the number of lines. Denote the file stored in the database as the file after storage, and the file downloaded to the local as the target file. Verify whether the number of lines of the file stored in the database after storage is consistent with the target file downloaded to the local. If they are consistent, it means that there is no problem with the file stored in the database after storage, then update the file batch acceptance success status and notify the file reading initiator that the file acceptance is successful; if they are consistent, it means that there is a problem with the file stored in the database after storage, then notify the file reading initiator that the file acceptance fails.
[0062] Regardless of whether the file acceptance is successful or not, enter the end processing method. In some embodiments of the present application, the processing logic of the end processing method includes: if the file acceptance is successful, delete the local temporary file and release the hardware resources occupied during the download process; if the file acceptance is not successful, release the hardware resources occupied during the download process after a preset duration.
[0063] If the file is successfully accepted, the local temporary file can be deleted immediately. As previously mentioned, if the target file is permanently saved locally, it can be deleted from the hardware resources; if it is cached locally, it can be deleted from the cache to free up space.
[0064] If the file is not successfully accepted, the local temporary file can be saved for a period of time, such as 24 hours, for use in cases such as resuming reading from a breakpoint.
[0065] During the above process, abnormal problems may be encountered. In response, this application sets an exception handling method. In some embodiments of this application, the exception handling method at least includes: when entering the processing logic of the exception handling method, deleting at least part of the target file stored in the database, or setting at least part of the file stored in the database to invalid; notifying the file reading initiating end that the file acceptance fails.
[0066] The reasons for entering the exception handling are diverse. For example, breakpoint resuming reading is not supported, the number of lines of the file stored in the database and the target file downloaded locally are inconsistent, the field value format does not meet the requirements during the file content line reading process, etc. In such cases, invalidation or deletion processing is performed, such as deleting at least part of the target file stored in the database, or setting at least part of the file stored in the database to invalid; and notifying the file reading initiating end that the file acceptance fails.
[0067] By Figure 1 As can be seen from the method shown, this application provides a reading method based on a template for program files. In this application, common parts such as cache files, parsing file lines and converting formats are encapsulated to form a common reading template, and the remaining parts with non-universal logic are abstracted to form a context-specific template. The context-specific template can be specified by the user with parameters to implement different logics; finally, the file is read according to the content of the context-specific template and the common reading template. This application splits the reading template of program files into a common part and a custom part, encapsulates the complex common processing process and abstracts the differences, not only supports user self-expansion, but also has a clear code structure; and this application can better accommodate different logics, improve reading accuracy, especially suitable for reading batch files, thus improving development efficiency; further, when developing business, there is no need to pay attention to the encapsulated file reading process logic outside the business, and only need to focus on the processing of business data, effectively improving the development work efficiency. When performing batch file processing, if the structure main body is the same, there is no need to review the code logic from scratch, and problems can be detected more quickly.
[0068] Figure 3 shows a schematic flow chart of a program file reading method according to another embodiment of this application. From Figure 3 it can be seen that this embodiment includes:
[0069] Display the context - setting template, where the context - setting template includes: file address, whether breakpoint - resuming reading is supported, the number of header lines of the file, the file line delimiter, and the file line object type.
[0070] Read the common reading template, where the common reading template includes: pre - processing method, file line reading method, post - processing method, exception - handling method, and end - handling method.
[0071] Confirm whether the target file exists on the server according to the file address, and the file name of the target file meets the preset requirements; if not, end the process.
[0072] If the target file exists and the file name of the target file meets the preset requirements, then determine whether the target file is for breakpoint - resuming transfer.
[0073] If it is for breakpoint - resuming transfer, then determine whether breakpoint - resuming transfer is supported. If breakpoint - resuming transfer is not supported, enter the exception - handling process; if breakpoint - resuming transfer is supported, continue to read the file content lines according to the current line number.
[0074] If the target file is not for breakpoint - resuming transfer, download the target file indicated by the file address from the server to the local.
[0075] Read several lines in the target file according to the number of header lines and convert them into a file header (the file header line reading process in the figure).
[0076] Perform the reading of the file content lines, determine whether the field value of a content line meets the preset requirements. If not, enter the exception - handling process. If it meets the requirements, convert each file content line into the corresponding data object according to the file line object type, and encapsulate the data objects corresponding to each file content line into a list. Determine whether the number of lines in the list reaches the preset threshold. If not, continue to read the file content lines. If the number of lines in the list reaches the preset threshold, perform batch storage of the data in the list into the database (the file content line reading process in the figure).
[0077] After the reading of the program file text is completed, verify whether the number of lines of the file stored in the database after batch storage is consistent with the number of lines of the target file downloaded to the local. If they are consistent, update the file batch acceptance success status and notify the file reading initiator that the file acceptance is successful; if they are inconsistent, end the process and enter the exception - handling stage.
[0078] Finally, all enter the processing logic of the end - handling method: if the file acceptance is successful, delete the local temporary file and release the hardware resources occupied during the download process; if the file acceptance is not successful, release the hardware resources occupied during the download process after a preset time period. The process ends.
[0079] Figure 4The structural schematic diagram of a program file reading device according to an embodiment of the present application is shown. Starting from Figure 4 As can be seen, the program file reading device 400 includes:
[0080] A custom parameter acquisition unit 410, configured to display a context - making template for filling, and the context - making template includes the following fields: file address, file line separator, and file line object type;
[0081] A common template reading unit 420, configured to read a common reading template, and the common reading template includes the following abstract methods: pre - processing method, file line reading method, post - processing method, exception handling method, and end - processing method;
[0082] A file reading unit 430, configured to read a file according to the content of the context - making template and the common reading template.
[0083] In some embodiments of the present application, in the above - mentioned device, the file reading unit 430 is specifically configured to verify whether a target file exists according to the file address. If it does not exist, the process ends; if the target file exists, it is determined whether the file name of the target file conforms to a preset specification. If it does not conform, the process ends; if the file name conforms to the preset specification, the target file is downloaded from the server to the local.
[0084] In some embodiments of the present application, in the above - mentioned device, the context - making template further includes: whether breakpoint resume reading is supported; the file reading unit 430 is specifically further configured to, before the step of downloading the target file from the server to the local, determine whether the target file is for breakpoint resume reading according to the existing content in the database. If not, directly execute the step of downloading the target file from the server to the local; if it is for breakpoint resume reading, determine whether breakpoint resume reading is supported. If breakpoint resume reading is supported, enter the processing logic of the file line reading method; if breakpoint resume reading is not supported, enter the processing logic of the exception handling method.
[0085] In some embodiments of the present application, in the above-mentioned device, the context formulation template further includes: the number of header lines of the file; the file reading unit 430, which is specifically further configured to determine whether the current process is a resume reading from a breakpoint. If not, it reads the header content of the target file downloaded to the local according to the number of header lines of the file. If it is a resume reading from a breakpoint, it skips the acquisition of the header content; reads the file content lines line by line. For a line of file content, it determines whether the field value type of the file content line exists and meets the preset requirements. If not, the process ends; if so, it converts each file content line into a corresponding data object according to the file line object type; encapsulates the data objects corresponding to each file content line into a list. When the number of lines in the list reaches the preset threshold, it performs batch data storage in the database.
[0086] In some embodiments of the present application, in the above-mentioned device, the file reading unit 430 is specifically further configured to verify whether the number of lines of the file stored in the database is consistent with the number of lines of the target file downloaded to the local. If they are consistent, it updates the successful status of file batch acceptance and notifies the file reading initiator that the file acceptance is successful; if they are inconsistent, the process ends and it notifies the file reading initiator that the file acceptance fails.
[0087] In some embodiments of the present application, in the above-mentioned device, the file reading unit 430 is specifically further configured to, when entering the processing logic of the exception handling method, delete at least part of the target file already stored in the database, or set at least part of the file already stored in the database to invalid; notify the file reading initiator that the file acceptance fails.
[0088] In some embodiments of the present application, in the above-mentioned device, the file reading unit 430 is specifically further configured to, if the file acceptance is successful, delete the local temporary file and release the hardware resources occupied during the download; if the file acceptance is not successful, release the hardware resources occupied during the download after a preset duration.
[0089] In some embodiments of the present application, in the above-mentioned device, the format of the file is a jxt file, the file delimiter is a vertical line delimiter, and the file line object type is the mapping relationship between the file columns and the program fields.
[0090] It should be noted that the above program file reading device can implement the foregoing program file reading method one by one, and details are not described herein again.
[0091] Figure 5 shows a schematic structural diagram of a computer device according to an embodiment of the present application. According to Figure 5As shown, the internal structure of the computer device may include a processor, a memory, a network interface, and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes non-volatile and / or volatile storage media, and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used to communicate with external clients via a network connection. When the computer program is executed by the processor, it realizes the functions or steps of the program file reading method.
[0092] In one embodiment, the computer device provided by the present application includes a memory and a processor. The memory stores a database and a computer program that can run on the processor. When the processor executes the computer program, the following steps are realized: displaying a context creation template for filling, where the context creation template includes the following fields: file address, file line delimiter, and file line object type;
[0093] Reading a common reading template, where the common reading template includes the following abstract methods: pre-processing method, file line reading method, post-processing method, exception handling method, and end processing method;
[0094] Reading the file according to the content of the context creation template and the common reading template.
[0095] In one embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by the processor, the following steps are realized:
[0096] Displaying a context creation template for filling, where the context creation template includes the following fields: file address, file line delimiter, and file line object type;
[0097] Reading a common reading template, where the common reading template includes the following abstract methods: pre-processing method, file line reading method, post-processing method, exception handling method, and end processing method;
[0098] Reading the file according to the content of the context creation template and the common reading template.
[0099] It should be noted that the functions or steps that can be realized by the above computer device or computer-readable storage medium can be referred to the relevant descriptions in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0100] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or an external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0101] Those skilled in the art can clearly understand that for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.
[0102] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for reading program files, characterized in that, Including: Display a context - making template for filling, and the context - making template includes the following fields: file address, file line delimiter, and file line object type; Read a common reading template, and the common reading template includes the following abstract methods: pre - processing method, file line reading method, post - processing method, exception - handling method, and end - handling method; Read the file according to the content of the context - making template and the common reading template.
2. The method according to claim 1, wherein The processing logic of the pre - processing method includes: Verify whether the target file exists according to the file address. If it does not exist, end the process; If the target file exists, determine whether the file name of the target file conforms to the preset specification. If it does not conform, end the process; If the file name conforms to the preset specification, download the target file from the server to the local.
3. The method according to claim 2, characterized in that, The context - making template further includes: whether breakpoint - resumed reading is supported; the processing logic of the pre - processing method further includes: Before the step of downloading the target file from the server to the local, determine whether the target file is for breakpoint - resumed reading according to the existing content in the database. If not, directly execute the step of downloading the target file from the server to the local; If it is for breakpoint - resumed reading, determine whether breakpoint - resumed reading is supported. If breakpoint - resumed reading is supported, enter the processing logic of the file line reading method; if breakpoint - resumed reading is not supported, enter the processing logic of the exception - handling method.
4. The method according to claim 1, wherein The context - making template further includes: the number of file header lines; the processing logic of the file line reading method includes: Determine whether the current process is for breakpoint - resumed reading. If not, read the file header content from the target file downloaded to the local according to the number of file header lines. If it is for breakpoint - resumed reading, skip the acquisition of the file header content; Read the file content lines line by line. For a file content line, determine whether the field value type of the file content line exists and meets the preset requirements. If not, end the process; if so, convert each file content line into a corresponding data object according to the file line object type; Encapsulate the data objects corresponding to each file content line into a list. When the number of lines in the list reaches the preset threshold, perform batch data storage in the database.
5. The method according to claim 1, wherein The processing logic of the post - processing method includes: Verify whether the number of lines of the file stored in the database is the same as that of the target file downloaded to the local. If they are the same, update the successful status of file batch acceptance and notify the file reading initiator that the file acceptance is successful; If they are not the same, end the process and notify the file reading initiator that the file acceptance fails.
6. The method according to claim 1, characterized in that The exception - handling method includes: When entering the processing logic of the exception - handling method, delete at least part of the target file stored in the database, or set at least part of the file stored in the database to invalid; Notify the file reading initiator that the file acceptance fails.
7. The method according to claim 1, characterized in that, The processing logic of the end - handling method includes: If the file acceptance is successful, delete the local temporary file and release the hardware resources occupied during the download process; If the file acceptance is not successful, release the hardware resources occupied during the download process after a preset duration.
8. The method according to any one of claims 1 to 7, characterized in that The format of the said file is a jxt file, the file delimiter is a vertical bar delimiter, and the file line object type is the mapping relationship between file columns and program fields.
9. A program file reading device, characterized in that The said device includes: A customized parameter acquisition unit, configured to display a context-defined template for filling, and the context-defined template includes the following fields: file address, file line delimiter, and file line object type; A common template reading unit, configured to read a common reading template, and the common reading template includes the following abstract methods: pre-processing method, file line reading method, post-processing method, exception handling method, and end processing method; A file reading unit, configured to read a file according to the content of the context-defined template and the common reading template.
10. A computer-readable storage medium storing a computer program, characterized in that, When the said computer program is instructed by a processor, it implements the steps of the file reading method according to any one of claims 1 to 8.