| |

VerySource

 Forgot password?
 Register
Search
View: 784|Reply: 5

About threads? ? ? ? ?

[Copy link]

4

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-5 18:00:01
| Show all posts |Read mode
import java.io. *;
class FileTest {
 public static void main (String [] args) throws Exception {
 File f = new File ("1.txt");
 f.createNewFile ();
 f.deleteOnExit ();
 Thread.sleep (30000); / * This code, I think it should be Thread.sleep (3000); and then f.deleteOnExit (); instead of now, how can this be the first time to get out and sleep for three seconds? ? ? ? ? * /
 Ranch
 Ranch
 Ranch
 }
}
 Please help me look at that problem ...
Reply

Use magic Report

4

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-6 06:39:01
| Show all posts
I add: the textbook says "call this method f.deleteOnExit (); and let the thread sleep."
 What's going on? ? ?
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-6 08:33:01
| Show all posts
What do you want to ask? What it means is to exit after 30 seconds. Give you time to see this file deleted.
If the thread does not sleep, maybe you have not seen the effect, the program has completed execution
Reply

Use magic Report

0

Threads

6

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-11 08:00:01
| Show all posts
Right upstairs, deleteeonexit () is deleted when you quit, it gives you 30 seconds. I guess I'm afraid to give you 3 seconds. You have deleted the file before you find it!
Reply

Use magic Report

1

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-11 09:45:02
| Show all posts
Not bad
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-11 12:00:02
| Show all posts
deleteOnExit
public void deleteOnExit () Requests the deletion of the file or directory represented by this abstract path name when the virtual machine terminates. Only when the virtual machine terminates normally will the delete operation be attempted, as defined in the Java Language Specification.
Once a delete operation has been requested, the request cannot be canceled. So use this method with caution.

Note: This method should not be used for file locking as the resulting protocol may not work reliably. FileLock facilities should be used instead.


Throws:
SecurityException-if a security manager exists and its SecurityManager.checkDelete (java.lang.String) method denies delete access to the file
Since:
1.2
See also:
delete ()
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