| |

VerySource

 Forgot password?
 Register
Search
View: 901|Reply: 6

A problem with the File class

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-4 23:00:01
| Show all posts |Read mode
try {
            rs.importApacheLog (file_log); // Call your own method;
            File bkup = new File (file_log);
            bkup.delete ();
        } catch (IOException e) {
            e.printStackTrace ();
        }

What do these two sentences mean? They were deleted after the establishment?
File bkup = new File (file_log);
bkup.delete ();
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-19 09:00:04
| Show all posts
It ’s not created, it should be said that it is loaded before it can be deleted.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-19 15:15:01
| Show all posts
Can you tell me the specific reason why this is not done?
Reply

Use magic Report

3

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-5-19 18:00:01
| Show all posts
File bkup = new File (file_log);
If file_log does not exist before, the operation will not create a related file.
If file_log exists bkup.delete (); will delete it, of course, you have to look at the file attributes
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-5-20 02:00:01
| Show all posts
rs.importApacheLog (file_log); // Call your own method;
// Data processing
 File bkup = new File (file_log);
 bkup.delete ();
// Get a reference to this backup file and delete
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Seychelles

 Author| Post time: 2020-5-20 07:30:01
| Show all posts
Equal to bkup.delete (); will delete both file_log file and bkup file
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-5-23 18:45:02
| Show all posts
File bkup = new File (file_log); This statement is to obtain a reference to this file. It is not to create it. If the file does not exist, it will only refer to an empty file. It will be generated when something is written to this reference. a new one.
The meaning of these two sentences is actually the same: delete that file.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list