The method and system that a kind of data are downloaded
Technical field
The invention belongs to field of network data transmission, and in particular to a kind of method that data are downloaded and
System.
Background technology
Terminal usually requires to download substantial amounts of data file to cache, and because a variety of causes number
According to meeting failed download.The method of such issues that existing solution has two kinds, and one kind is to work as user's point
Go to download this file again when hitting the file for needing to browse.Another is when there is network, according to net
The order of network request removes downloading data file, when downloading mass data file, and record, which is downloaded, to be lost
The file lost, the file download of searching loop failure, until failed download number is zero.
First method can only rely on current network environment, when user is not connected with network, only
The limited file downloaded can be browsed.In second method, because network request can take net
Network resource so that user interface (UI) was reacted slowly, so as to cause poor user experience;It is another
Aspect, frequently network request can cause terminal hardware loss it is too fast, such as hardware heating, performance
It is deteriorated.
The content of the invention
The technical problems to be solved by the invention are how to reduce the difficult text downloaded or can not downloaded
Resource occupation in the download frequency and downloading process of part, saves the system in file download process
Expense.
For the technical problem, the present invention proposes a kind of method that data file is downloaded, including:
S1:Obtain the information of the failed download number of times of the data file of failed download;
S2:The data text is downloaded successively according to the order of the failed download number of times from small to large
Part.
Preferably, also include after the step S2:
S3:Judge whether the data file is all downloaded successfully, if so, stopping to the data
The download of file, otherwise, the step S1 is performed after waiting preset time period.
Preferably, current data file download time point away from last data file download when
Between put longer, the preset time period is longer.
Preferably, the step S1 includes:
S11:From the data file obtained in advance obtain failed download data file and
The failed download number of times of the data file of each failed download;
S12:According to data of the order of the failed download number of times from small to large to failed download
File is ranked up, and generates data file sequence;
Wherein, the data file be used for record each data file whether download successfully with
The number of times of failed download.
Preferably, the step S2 includes:
S21:The data are judged successively according to the order of the failed download number of times from small to large
Whether the number of times of the data file failed download in file sequence exceedes preset times, until downloading
The number of times of failure exceedes the preset times;
S22:Download successively in the data file sequence failed download number of times exceed first it is described
All data files before preset times.
On the other hand, the invention provides the system that a kind of data file is downloaded, including:
Acquisition module, the letter of the failed download number of times of the data file for obtaining failed download
Breath;
Download module, for being downloaded successively according to the order of the failed download number of times from small to large
The data file.
Preferably, in addition to the first judge module, in the download module to the data
After file is downloaded, judge whether the data file is all downloaded successfully, if so, stopping pair
The download of the data file, otherwise, the step S1 is performed after waiting preset time period.
Preferably, current data file download time point away from last data file download when
Between put longer, the preset time period is longer.
Preferably, in addition to arrangement module;
The acquisition module is additionally operable to obtain to download from the data file obtained in advance to lose
The data file and the failed download number of times of the data file of each failed download lost;
The arrangement module is used for according to failed download number of times order from small to large under
The data file for carrying failure is ranked up, and generates data file sequence;
Wherein, the data file be used for record each data file whether download successfully with
The number of times of failed download.
Preferably, in addition to the second judge module;
Second judge module is used for the order according to the failed download number of times from small to large
Judge whether the number of times of the data file failed download in the data file sequence exceedes successively
Preset times, until the number of times of failed download exceedes the preset times;
The download module is additionally operable to download failed download in the data file sequence successively
Number exceedes all data files before the preset times first.
In the method and system that the data file that the present invention is provided is downloaded, according to the number to be downloaded
According to the number of times statistical result of the failed download of file, preferentially the data few to failed download number of times are literary
Part is downloaded, meanwhile, the time interval downloaded each time is relative to the preceding time once downloaded
Interval gradually increases.Over time with the data file failed download number of times of failed download
Increase, in the download frequency and downloading process that reduce the difficult file downloaded or can not downloaded
Resource occupation, has saved the overhead in file download process.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below
The required accompanying drawing used in embodiment or description of the prior art will be briefly described, shown
And easy insight, drawings in the following description are some embodiments of the present invention, general for this area
, on the premise of not paying creative work, can also be attached according to these for logical technical staff
Figure obtains other accompanying drawings.
Fig. 1 is the flow chart for the method that the data file that one embodiment of the invention is provided is downloaded;
Fig. 2 is the text of the data on restarting downloading process that another embodiment of the present invention is provided
The flow chart for the method that part is downloaded;
Fig. 3 is the time interval for the downloading process startup that one embodiment of the invention is provided under
Carry the change curve of number of times;
Fig. 4 is download of the data file of one embodiment of the invention offer on starting the time
Method in flow chart;
Fig. 5 is the structural frames for the system that the data file that one embodiment of the invention is provided is downloaded
Figure.
Embodiment
, below will knot to make the purpose, technical scheme and advantage of the embodiment of the present invention clearer
The accompanying drawing in the embodiment of the present invention is closed, clear to the technical scheme progress in the embodiment of the present invention,
It is fully described by, it is clear that described embodiment is a part of embodiment of the invention, rather than
Whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art are not having
The every other embodiment obtained under the premise of creative work is made, protection of the present invention is belonged to
Scope.
Embodiment 1:
A kind of method that data file is downloaded is present embodiments provided, as shown in figure 1, including:
Step S1:Obtain the information of the failed download number of times of the data file of failed download;
Step S2:According to the order of failed download number of times from small to large successively downloading data file.
The information of the failed download number of times of the data file of failed download can be by under access
The data file for carrying failure obtains or downloads situation by accessing record data file
Record is obtained.
When being downloaded to the file of failed download, according to data file failed download number of times according to
It is secondary to download.The number of times less data file of failed download is more relative to failed download number of times
For data file, successful probability is downloaded bigger.The preferential number of times to failed download is less
Data file is downloaded, and the time shared by downloading process is shorter.On the other hand, with when
Between passage and failed download data file failed download number of times accumulation, reduce under
Carry the probability that the larger data file of number of times is downloaded, difficult download or can not download so as to reduce
Resource occupation in the download frequency and downloading process of file, has been saved in file download process
Overhead.
It should be noted that:Because the download of data file relies on certain network environment, therefore
In order to avoid opening downloading process in the case of without network connection, step S1 can be right
Network environment is carried out again after being judged.If current network is in connection status, step is performed
S1, if current network is off, does not start downloading process.
The method that the data file that the present embodiment is provided is downloaded, according to the data file to be downloaded
Failed download number of times statistical result, preferentially the data file few to failed download number of times carry out
Download, meanwhile, the time interval downloaded each time relative to the preceding time interval once downloaded by
It is cumulative to add.Over time with the increasing of the data file failed download number of times of failed download
Plus, reduce the resource in the download frequency and downloading process of the difficult file downloaded or can not downloaded
Take, saved the overhead in file download process.
Embodiment 2:
On the basis of embodiment 1, the method for down loading for the data file that the present embodiment is provided is as schemed
Shown in 2, also include after step S2:
Step S3:Judge whether data file is all downloaded successfully, if so, stopping to data text
The download of part, otherwise, waits and step S1 is performed after preset time period.
The data file of failed download is by may all download after step S2 successfully or still
There is the file of failed download.Upon step s 2, the download shape of the file of failed download is updated
The record of state, if still failed download upon step s 2, adds 1 by the number of times of failed download,
If downloading successfully, the download state of data file is updated to download successfully.
After step S2, judged whether by the download status information of the data file after renewal
All data files download success, if so, stopping the download to data file.Further
Ground, can be sent out prompt message.If still there is the data file of failed download after step S2,
Rebound step S1, is downloaded to the file of failed download.
It should be noted that:In the method for down loading for the data file that the present embodiment is provided, in step
It is not to immediately begin to the download to the data file of failed download after S2, and is to wait for pre-
If performing S1 after the period again, the file of failed download is downloaded.
Preset time period is between the time point for the adjacent downloading process twice being manually set
Time interval.Perform after step S2, downloading process is opened to current point in time and last time
Time point between time interval judged, if the time interval be more than or equal to preset time
Section, then open downloading process, is otherwise opened down after the time interval is more than or equal to preset time period
Load process.
In the method for down loading for the data file that the present embodiment is provided, to adjacent downloading process twice
Between time interval limited, it is to avoid the network condition in similar time section is tied to downloading
The influence really brought and frequent downloads improve Internet resources to the lasting occupancy of Internet resources
Utilization rate.
Embodiment 3:
A kind of method to set up of the preset time period proposed in embodiment 2 is present embodiments provided,
Body, the time point that current data file is downloaded gets over away from the time point that last data file is downloaded
Long, preset time period is longer.
Preset time period refers to the time point of current data file download away from last data file
Time interval between the time point of download.The time interval is longer, and preset time period is also longer.
For example, calculating preset time period by below equation.
Wherein, n is the natural number more than or equal to 0;When T (n) is that current data file is downloaded
Between put time interval between the time point downloaded away from data file next time, that is, when default
Between section;T (n-1) is to be downloaded away from last data file at the time point that current data file is downloaded
Time interval between time point;N=0 represents that the downloading process currently opened is to download first
Journey, the process that the data file that will start is downloaded is second of downloading process.
The calculating process explanation of above preset time period:When starting downloading process first, next time
The time that downloading process starts is 20 seconds, then is exactly 2 × 20=40 seconds next time, i.e., ought restart
When the time interval of downloading process is less than 1 day, according to the interval of 2 × T every time (n-1) (second)
Restart and download flow next time.
The time point that the time point that current data file is downloaded is downloaded away from last data file it
Between time interval be more than or equal to 1 day be less than 7 days, then the time interval ratio started next time
A upper time interval is more 1 day.It is 1 day for example to re-download time interval last time, then next time be
2 days, be 3 days again.
Line time interval was downloaded more than or equal to 7 days less than 30 days when restarting, according to each
The time interval of increase by 7 days, which is restarted, downloads flow next time, for example, re-download time interval last time
It it is 1 week, then next time is 2 weeks, is 3 weeks again.Downloaded line time interval when restarting and be more than
Or during equal to 1 month (being calculated according to 30 days), then re-downloaded and do not download at interval of 30 days
Data file.
Fig. 3 is the time interval schematic diagram for the continuous download that the present embodiment is provided, can be with from Fig. 3
Find out, over time, the time interval for starting downloading process every time is longer, downloads and loses
The download probability of the file lost is just smaller, so as to reduce the difficult data downloaded or can not downloaded
Probability of the file to resource occupation.
In the computational methods for the preset time period that the present embodiment is provided, referring under previous startup
The time interval of load process sets the time interval that this downloading process starts, it is contemplated that current
Network environment, it is to avoid network congestion that frequently repeated downloads are brought and resource long-term take.
Embodiment 4:
On the basis of embodiment 1, step in the data file downloading method that the present embodiment is provided
S1 includes:
S11:From the data file obtained in advance obtain failed download data file and
The failed download number of times of the data file of each failed download;
S12:According to data file of the order of failed download number of times from small to large to failed download
It is ranked up, generates data file sequence;
Wherein, data file is used to record whether each data file is downloaded successfully and downloaded
The number of times of failure.
Step S2 includes:
S21:The data are judged successively according to the order of the failed download number of times from small to large
Whether the number of times of the data file failed download in file sequence exceedes preset times, until downloading
The number of times of failure exceedes the preset times;
S22:Download successively in the data file sequence failed download number of times exceed first it is described
All data files before preset times.
The download information for the acquisition data file that conducted interviews to data file is convenient and swift, further
The Download History in order to quickly find data file can also by Hash table by data text
The download information of part and data file is stored, to improve the speed in search procedure.
Data file has small to big order according to the number of times of failed download in data file sequence
Arrangement, it is convenient that data file is downloaded according to the number of times of failed download.
Preset times are a values set in advance, can rule of thumb be obtained, and reaction is downloaded
Numerical value between number of times and the successful probability of download.If the number of times of data file failed download exceedes
The preset times, it is very low that data file downloads successful probability.
Further, the failed download from data file sequence successively to each data file
It is several to be judged, will be no longer to data when the number of times for failed download occur exceedes preset times
The failed download number of times that data file behind is arranged in file sequence is judged.In data
During file download, only the data file before the data file is downloaded.
In the method for down loading for the data file that the present embodiment is provided, by accessing data file
Data file download time information is obtained, the time to download time acquisition of information is saved.Together
When, the foundation of data file sequence is convenient that data file is downloaded and judged successively.
Whether sentencing for preset times is exceeded to the number of times of data file download failure in data file sequence
It is disconnected, it is to avoid the data file for exceeding to failed download number of times preset times carries out repeated downloads band
The wasting of resources come.
Embodiment 5:
Fig. 4 is the method flow diagram that the data file that the present embodiment is provided is downloaded, referring to Fig. 4,
In this method, ergodic data file record first obtains the data file of failed download and corresponding
Failed download number of times.According to data file failed download number of times order from small to large according to
Secondary downloading data file.Complete after this downloading process, the download state to data file is carried out
Judge and update.In the data file after the number of times of download state and failed download updates
Judge whether that all data files download success, if so, terminating downloading process.Otherwise,
Prepare to start downloading process next time.
Starting next time before downloading process, period of wait (now time point and is being worked as
Time interval between the preceding time point for downloading data file) judged, if the stand-by period is super
Preset time period is crossed, downloading process is restarted.Otherwise, periodically the stand-by period is carried out
Judge, until the stand-by period exceedes after preset time period, restart downloading process.
In the method for down loading for the data file that the present embodiment is provided, according to the data text to be downloaded
The number of times statistical result of the failed download of part, preferentially the data file few to failed download number of times enter
Row is downloaded, and starts the setting of the time interval of downloading process every time, it is to avoid network environment
Influence to downloading result, reduce the difficult file downloaded or can not downloaded download frequency and under
Resource occupation during load, has saved the overhead in file download process.
Embodiment 6:
The system A that a kind of data file is downloaded is present embodiments provided, as shown in figure 5, including:
Acquisition module A1, the failed download number of times of the data file for obtaining failed download
Information;
Download module A2, for according to failed download number of times order from small to large successively
Download the data file.
The system that the data file that the present embodiment is provided is downloaded, download module A2 is according to acquisition mould
The number of times statistical result of the failed download for the data file to be downloaded that block A1 is obtained is preferential right
The few data file of failed download number of times is downloaded.Meanwhile, the time interval downloaded each time
Gradually increase relative to the preceding time interval once downloaded.Over time and failed download
Data file failed download number of times increase, reduce the difficult file downloaded or can not downloaded
Resource occupation in download frequency and downloading process, the system saved in file download process is opened
Pin.
Embodiment 7:
On the basis of embodiment 6, the system that data file is downloaded also judges mould including first
Block, for after the download module is downloaded to the data file, judging the data
Whether file is all downloaded successfully, if so, stop the download to the data file, otherwise, etc.
After performing the step S1 after preset time period.
Wherein, the time that the time point that current data file is downloaded downloads away from last data file
Point is longer, and the preset time period is longer.
In the download system for the data file that the present embodiment is provided, the first judge module is to adjacent two
Time interval between secondary downloading process is judged that download module is sentenced according to judge module
Determine result to be downloaded, it is to avoid what the network condition in similar time section was brought to downloading result
Influence and frequent downloads improve the utilization of Internet resources to the lasting occupancy of Internet resources
Rate.Set what this downloading process started referring to the time interval of previous startup downloading process
Time interval, it is contemplated that current network environment, it is to avoid the net that frequently repeated downloads are brought
Network congestion and resource long-term take.
Embodiment 8:
On the basis of embodiment 1, in the system that the data file that the present embodiment is provided is downloaded,
Also include arrangement module and the second judge module;
The acquisition module is additionally operable to obtain to download from the data file obtained in advance to lose
The data file and the failed download number of times of the data file of each failed download lost;
The arrangement module is used for according to failed download number of times order from small to large under
The data file for carrying failure is ranked up, and generates data file sequence;
Wherein, the data file be used for record each data file whether download successfully with
The number of times of failed download.
Second judge module is used for the order according to the failed download number of times from small to large
Judge whether the number of times of the data file failed download in the data file sequence exceedes successively
Preset times, until the number of times of failed download exceedes the preset times;
The download module is additionally operable to download failed download in the data file sequence successively
Number exceedes all data files before the preset times first.
In the download system for the data file that the present embodiment is provided, acquisition module is by accessing data
File record obtains data file download time information, saves to download time acquisition of information
Time.Meanwhile, foundation of the arrangement module to data file sequence, conveniently to data file successively
It is downloaded and judges.Second judge module in data file sequence to data file download to losing
Whether the number of times lost exceedes the judgement of preset times, it is to avoid failed download number of times is exceeded default
The data file of number of times carries out the wasting of resources that repeated downloads are brought.
The preferred embodiments of the present invention are the foregoing is only, are not intended to limit the invention,
For those skilled in the art, the present invention can have various modifications and variations.It is all this
Within the spirit and principle of invention, any modification, equivalent substitution and improvements made etc. all should
Within protection scope of the present invention.