import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FlashMemoryExample {
public static void main(String[] args) {
Path flashDrivePath = Paths.get("/path/to/your/flash/drive"); // Replace with the actual path
Path filePath = flashDrivePath.resolve("myFile.txt");
try {
// Write to file
Files.write(filePath, "Hello from Java!".getBytes());
System.out.println("Data written to flash memory");
// Read from file
String content = new String(Files.readAllBytes(filePath));
System.out.println("Data read from flash memory: " + content);
} catch (IOException e) {
System.err.println("Error accessing flash memory: " + e.getMessage());
}
}
}
No comments:
Post a Comment