Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

File IO Operations: Opening and closing files

Verilog Examples

Runnable example from the Verilog File IO Operations tutorial (Opening and closing files)

Open in IDE
testbench.v
module tb;
  // Declare a variable to store the file handler
  integer fd;

  initial begin
    // Open a new file by the name "my_file.txt"
    // with "write" permissions, and store the file
    // handler pointer in variable "fd"
    fd = $fopen("my_file.txt", "w");

    // Close the file handle pointed to by "fd"
    $fclose(fd);
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.