gpt4 book ai didi

file - 如何将数据 append 到现有文件

转载 作者:行者123 更新时间:2023-12-04 20:05:33 24 4
gpt4 key购买 nike

在 Chapel 中,我们可以使用 open() 打开一个文件进行写入。 + iomode.cw ,例如,

var fout = open( "foo.dat", iomode.cw );   // create a file for writing
var cout = fout.writer(); // make a channel
cout.writeln( 1.23 );
cout.close();
fout.close();

或通过 openwriter() 建立 channel 作为
var cout = openwriter( "foo.dat" );
cout.writef( "n = %10i, x = %15.7r\n", 100, 1.23 );
cout.close();

但似乎没有对应于“追加”模式的选项(在 IO 页面中)。目前是否没有提供,如果是,是否有任何惯用的方法来打开文件并 append 数据?

最佳答案

从 Chapel 1.20 开始,不支持 IO 的追加模式。在支持之前,您可以使用以下解决方法:

// Open a file for reading and writing
var fout = open("foo.dat", iomode.rw);

// Position a writing channel at the end of the file
var cout = fout.openAppender();

cout.writeln(1.23);

cout.close();
fout.close();

/* Create a writer channel with a starting offset at the end of the file */
proc file.openAppender() {
var writer = this.writer(start=this.length());
return writer;
}

在 Chapel GitHub 问题中有一个对追加模式的开放功能请求。见问题 #9992想要查询更多的信息。

关于file - 如何将数据 append 到现有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59753273/

24 4 0
文章推荐: asp.net-mvc-3 - 困惑 : Why to do i have to map my entity object to viewmodel object
文章推荐: axapta - 如何强制查询范围?
文章推荐: wcf - 服务 '' 的应用程序(非基础设施)端点为零
文章推荐: css - 使用 -moz-transform 解决损坏的