Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
15
Task/Secure-temporary-file/C++/secure-temporary-file.cpp
Normal file
15
Task/Secure-temporary-file/C++/secure-temporary-file.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <cstdio>
|
||||
|
||||
int main() {
|
||||
// Creates and opens a temporary file with a unique auto-generated filename.
|
||||
// If the program closes the file, the file is automatically deleted.
|
||||
// The file is also automatically deleted if the program exits normally.
|
||||
std::FILE* temp_file_pointer = std::tmpfile();
|
||||
|
||||
// Using functions which take a file pointer as an argument
|
||||
std::fputs("Hello world", temp_file_pointer);
|
||||
std::rewind(temp_file_pointer);
|
||||
char buffer[12];
|
||||
std::fgets(buffer, sizeof buffer, temp_file_pointer);
|
||||
printf(buffer);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
printfn $"%s{System.IO.Path.GetTempFileName()}"
|
||||
25
Task/Secure-temporary-file/Java/secure-temporary-file-2.java
Normal file
25
Task/Secure-temporary-file/Java/secure-temporary-file-2.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import java.io.BufferedWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public final class SecureTemporaryFile {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// Create a temporary file in the directory D:\.
|
||||
// We should use java.nio.file.Files instead of the old java.io.File, as it is more secure.
|
||||
// If the file cannot be created, it will throw an exception.
|
||||
Path temporaryFilePath = Files.createTempFile(Path.of("D:/"), "example", ".tmp");
|
||||
|
||||
// For uniqueness, the Java API will insert a random number between the given prefix
|
||||
// and the file extension.
|
||||
System.out.println("Temporary file created: " + temporaryFilePath);
|
||||
|
||||
// Opening it with the following option will cause the file to be deleted when it is closed.
|
||||
BufferedWriter tempFileWriter = Files.newBufferedWriter(
|
||||
temporaryFilePath, StandardOpenOption.DELETE_ON_CLOSE);
|
||||
// ... write to file, read it back in, close it...
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
// version 1.1.2
|
||||
import kotlin.io.path.createTempFile
|
||||
import kotlin.io.path.deleteExisting
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
val tf = File.createTempFile("temp", ".tmp")
|
||||
println(tf.absolutePath)
|
||||
tf.delete()
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
println(ex.message)
|
||||
}
|
||||
fun main() {
|
||||
val tempFilePath = createTempFile("example", ".tmp")
|
||||
println("Temporary file created: $tempFilePath")
|
||||
tempFilePath.deleteExisting()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue