使用属性创建文件并在逻辑中发布

时间:2015-05-22 07:59:30

标签: java

是SAP PI场景..   有2个字段:registeration_id和Transaction_id  最初我将使Transaction_id和registeration_id为1.应该生成文件,直到Transaction_id达到9999并且文件应该包含registeration_id和Transaction_id的更新值。但是一旦达到9999,registeration_id应该变为2并且应该创建文件

我尝试了以下代码

static int regId=1;
static int transID=1;
public static void main(String args[])
{
    int i;
    //int ilength = 0;
    for(i=1;i<=9999;i++)
    {

        if(transID!=9999)
        {
            //System.out.println(transID);
            Properties properties = new Properties();
            File propertiesfile = new File("Sequence.properties");
            try {
                propertiesfile.createNewFile();
                properties.load(new FileInputStream(propertiesfile));
            }
            catch (IOException e)
            {
                e.printStackTrace();
                System.out.println("Error:File not read");
            }




            if(transID!=97)
            {
                transID++;
                System.out.println(transID);
            }
            else
            {
                transID=99;
            }
            break;
        }
        else
        {
            if(regId!=1 && regId!=8)
            {
                regId++;
                System.out.println(regId);
            }
            else if(regId==1)
            {
                regId=3;
                System.out.println(regId);
            }
            else
            {
                regId=10;
            }
        }

但我收到错误..请提供您宝贵的意见

2 个答案:

答案 0 :(得分:0)

我完全不在你身上,但也许这会奏效:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Snippet {
    static int  regId   = 1;
    static int  transID = 1;

    public static void main(String args[]) {
        int i;
        // int ilength = 0;
        for (i = 1; i <= 9999; i++) {

            if (transID != 9999) {
                // System.out.println(transID);
                Properties properties = new Properties();
                File propertiesfile = new File("Sequence.properties");
                try {
                    propertiesfile.createNewFile();
                    properties.load(new FileInputStream(propertiesfile));
                } catch (IOException e) {
                    e.printStackTrace();
                    System.out.println("Error:File not read");
                }

                if (transID != 97) {
                    transID++;
                    System.out.println(transID);
                } else {
                    transID = 98;
                }
//              break;
            } else {
                if (regId != 1 && regId != 8) {
                    regId++;
                    System.out.println(regId);
                } else if (regId == 1) {
                    regId = 3;
                    System.out.println(regId);
                } else {
                    regId = 10;
                }
            }
        }
    }
}

答案 1 :(得分:0)

与krzys相同的问题,你想要的并不完全清楚。

    public static void main(String args[]){
    // #1 initially transaction_id=1 and registeration_id=1
    int regId = 1;  // not used?
    int transID = 1;

    int i =0;

    while(i<9999){
        i++;
        // assuming:
        transID++;
        regId++;

        // #4 once transaction_id reaches 9999, reset transaction_id=1 registeration_id =03(NOTE: skip 02 and 09 for registeration_id )
        if(transID==9999){
            transID = 1;
            regId= 3;
        } else{
            // #2 if transaction_id is not equal to 9999
            // create file increment transaction_id
            Properties properties = new Properties();
            File propertiesfile = new File("Sequence.properties");
            try {
                propertiesfile.createNewFile();
                properties.load(new FileInputStream(propertiesfile));
            }
            catch (IOException e){
                e.printStackTrace();
                System.out.println("Error:File not read");
            }

            // #3 if transaction_id = 97
            //    skip 98 and transaction_id should become 99
            if(transID==98){
                transID++;
                System.out.println(transID);
            }
            System.out.println("transID: " + transID +", regID: " + regId);
        }
    }
}

所以我试着将你的规范直接放在源代码中。