首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从文本文件中获取值

如何从文本文件中获取值
EN

Stack Overflow用户
提问于 2015-03-18 13:08:37
回答 1查看 92关注 0票数 1

My problem:我需要从一个文本文件中获取几个值。

我正在开发一个解析器,从ttcn-3语言到XML语言,我需要做的是从ttcn模块中获取一些关键字和值,ttcn模块是用文本文件来构建XML文件的。

这里是我的ttcn代码的开始:

代码语言:javascript
复制
module SessionSetup
{
type port InputPortType message { in charstring }
type port OutputPortType message { out charstring }
type component SessionSetupResComponentType {
    port InputPortType InputPort;
    port OutputPortType OutputPort;
}

例如,我需要得到紧跟在模块(SessionSetup)之后的字符串,下面是我编写的代码:

代码语言:javascript
复制
public  void ReadTheFileGetTheModuleName(String fichier){
            try{
                InputStream ips=new FileInputStream(fichier); 
                InputStreamReader ipsr=new InputStreamReader(ips);
                BufferedReader br=new BufferedReader(ipsr);
                String ligne;

                while ((ligne=br.readLine())!=null){
                    if (ligne.contains("module"))
                    {
                        String[] st = ligne.split(ligne, ' ');
                        System.out.println("Nom = "+st[1]);
                    }

                    chaine+=ligne+"\n";

                }
                br.close();
            }       
            catch (Exception e){
                System.out.println(e.toString());
            }
        }

问题是,它不工作,我没有得到一个接一个模块字符串。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-18 13:12:01

代码语言:javascript
复制
 String[] st = ligne.split(ligne, ' ');
                       /\/\/\/\/\/\/\
                 Incorrect way, pass some regex on which string should split

您的String#Split()方法出错,请检查文档

应该是这样的

代码语言:javascript
复制
public String[] split(String regex, int limit)

or

public String[] split(String regex)

注意:您不会得到编译时错误,因为split()方法中的(‘')是一个字符,可以隐式类型为Integer。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29122967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档