方法一:
static void Job30(Args _args) { TextIo m_CSVFile; container m_con; InventTable m_inventTable; int i; #File ; m_CSVFile =new TextIo(@"D:\\Item.txt",#io_write); if(!m_CSVFile || m_CSVFile.status() != IO_Status::Ok) throw error("访问磁盘失败!"); while select m_inventTable { i++; if(i>2) break; m_con = [m_inventTable.ItemId]; m_CSVFile.writeExp(m_con); } }
方法二:
static void Job_TextIO(Args _args) { TextIo textIo; #File ; textIo = new TextIo(@"D:\\Job_TextIO.txt", #IO_WRITE); textIo.write("Line 1"); textIo.write("Line 2"); }
方法三:
static void Job_StreamWriter(Args _args) { System.IO.StreamWriter sw; InteropPermission perm = new InteropPermission(InteropKind::ClrInterop); ; perm.assert(); sw = new System.IO.StreamWriter(@"D:\\Job_StreamWriter.txt"); sw.WriteLine("Line 1"); sw.WriteLine("Line 2"); sw.Flush(); sw.Close(); sw.Dispose(); CodeAccessPermission::revertAssert(); }
方法四:
作业打开文件进行写入(截断现有文件或创建新文件),设置字段和记录分隔符,然后将同一行写入两次(使用两个不同的调用)。对 write
的最后一次调用附加了记录分隔符
static void TextIoTest(Args _args) { /*假设我有一个大小为10的字段值,但字段大小固定为20,所以当下一个字段到来 时,它应该插入位置21,用空格填充第一个字段的剩余10个空格。*/ TextIo f = new TextIo(@"D:\TextIoTest.txt", 'w'); ; f.outFieldDelimiter(''); f.outRecordDelimiter('\r\n'); f.write( strLfix("abc",20), '|', strRfix("xyz",15), '|', 117); f.writeExp([strLfix("abc",20), '|', strRfix("xyz",15), '|', 117]); f.write();//To force CR NL }
可以使用 strrep
, substr
和 strpoke
,请在 \ Classes \ VendOutPaymRecord_UK_BACS \ output
中找到示例。
方法五:
static void Job31(Args _args) { AsciiIo diskFile; Filename diskFileName; str line; container c; ; c = [1,"MyTest",2,"HisText"]; diskFileName = @"D:\\test.txt"; diskFile = new AsciiIo(diskFileName,'W'); diskFile.outRecordDelimiter('\r\n'); diskFile.outFieldDelimiter(";"); diskFile.writeExp(c); }
留言评论
暂无留言