vala文件读取与文件写入示例代码

代码语言:vala

所属分类:文件

代码描述:vala文件读取与文件写入示例代码

代码标签: 文件 写入 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

int main () {
    try {

        // Reference a local file name
        var file = File.new_for_path ("/data/wwwroot/default/Data/vala.txt");

        
               // delete if file already exists
        if (file.query_exists ()) {
                file.delete ();
        }
            // Create a new file with this name
        var file_stream = file.create (FileCreateFlags.NONE);

            // Test for the existence of file
        if (file.query_exists ()) {
                stdout.printf ("File successfully created.\n");
        }

            // Write text data to file
        var data_stream = new DataOutputStream (file_stream);
        data_stream.put_string ("Hello, world");
         // Streams closed at this point

        // Open file for reading and wrap returned FileInputStream into a
        // DataInputStream, so we can read line by line
        var dis = new DataInputStream (file.read ());
        string line;
        // Read lines until end of file (null) is reache.........完整代码请登录后点击上方下载按钮下载查看

网友评论0