• 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();
        */
    
    }
    
    
  • 相关阅读:
    linux安装jenkins
    如何将接口进行限流
    java线程池思想
    一次缓存评估过程
    docker
    linux基本操作
    【安卓】App自动化环境搭建
    sheill之文本处理工具
    Liunx vim编辑器
    Liunx 远程
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1886833.html
Copyright © 2020-2023  润新知