java - 如何将 java.lang.String 转换为 java.util.Timer?

标签 java string types timer

我正在读取属性文件

actiontimer = properties.getProperty("action1");

我得到一个字符串,并希望将其转换为计时器以便稍后在我的程序中使用它。

private Timer actiontimer

类型转换不起作用,我得到:

Cannot cast from String to Timer

我该如何进行此类型转换?

更新:

属性文件中的格式:

action1:12314

最佳答案

将字符串转换为整数。

现在使用[Timer's Schedule]传递一个 int 作为参数。

   String s = "12314"; 
        Integer delay = Integer.parseInt(s);
        Timer timer = new Timer(); 
        TimerTask task = new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

            }
        };
        timer.schedule(task, delay);

关于java - 如何将 java.lang.String 转换为 java.util.Timer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13527668/

相关文章:

java - 打开文件;首先尝试文件系统,然后尝试 JAR

java - 无法实例化 parceable 对象

java - 字符串连接 : concat() vs "+" operator

java - 比较java中的两个整数字符串

Symfony2 Doctrine自定义类型生成不需要的迁移

iphone - iOS 5 : Set min and max value of input type ="date"

c++ - 确保 C++ double 为 64 位

java - Spring 方法存在于代码中,但不存在于 JAR 中

java - FirebaseStorage.getReferenceFromUrl(来源未知)

java - 有时缺少年份而有时不缺少年份时将字符串解析为日期