• Write and Read Text file usage to AX 2009


    static void Jimmy_FileTextIoWriteRead(Args _args)
    {
        TextIo              txIoRead,txIoWrite;
        FileIOPermission    fioPermission;
        container           ConData;
        int                 xx,LenData;
        str                 sTempPath,
                            sFileName = "Test_File_IO.txt",
                            sOneRecord;;
    
        sTempPath = WINAPI::getTempPath();// Get the temporary path.//info("File is at: " + sTempPath + sFileName);
        
    
        // Assert permission.
        fioPermission = new FileIOPermission(sTempPath + sFileName ,"RW");
        fioPermission.assert();
    
        // If the test file already exists, delete it.
        if (WINAPI::fileExists(sFileName))
            WINAPI::deleteFile(sTempPath + sFileName);
    
    
        // Open a test file for writing.
        // "W" mode overwrites existing content, or creates the file.
        txIoWrite = new TextIo( sTempPath + sFileName ,"W");
    
        // Write records to the file.
        txIoWrite.write("Start.....");
        txIoWrite.write("Everybody good evening, my name is Xie YuFan and English name is Jimmy, I am come from China, I am a ERP software engineer.  I enjoy my work very much!");
        txIoWrite.write("I hope here to realize more friends around the world.");
        txIoWrite.write("My blog is : http://www.cnblogs.com/Jimmyx/");
        txIoWrite.write("QQ : 332469390");
        txIoWrite.write("end.....");
    
    
    /***********************************************************/
        
        txIoRead = null;// Close the test file.
        txIoRead = new TextIo(sTempPath + sFileName ,"R");// Open the same file for reading.
        ConData = txIoRead.read(); // Read the entire file into a container.
    
        
        while (ConData) // Loop through the container of file records.
        {
            sOneRecord  = "";
            LenData     = conLen(ConData);
            
            for (xx=1; xx <= LenData; xx++) // Loop through the token in the current record.
            {
                if (xx > 1) sOneRecord += " ";
                sOneRecord += conPeek(ConData ,xx);
            }
            info(sOneRecord);
            ConData = txIoRead.read();// Read the next record from the container.
        }
       
        txIoRead = null; // Close the test file.
        WINAPI::copyFile(sTempPath + sFileName,@"c:\\" +sFileName,true);
    
        /*
        if(WINAPI::fileExists(sTempPath + sFileName)) // Delete the test file.
            WINAPI::deleteFile(sTempPath + sFileName);
    
        revertAssert is not really necessary here,
         because the job (or method) is ending.
        CodeAccessPermission::revertAssert();
        */
    
    }
    
    
  • 相关阅读:
    JS中iframe子页面与父页面之间通信
    .NET 大数据量并发解决方案
    angular的性能分析 -随记
    第二次作业
    自我介绍
    总结作业
    2019春第四次课程设计实验报告
    2019春第三次课程设计实验报告
    2019春第二次课程设计实验报告
    第十二周作业
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1886833.html
Copyright © 2020-2023  润新知