String-->bytes-->Stream-->Properties

解决方案 »

  1.   

    你说的是不是显示一段文章,你直接从DB里读取,然后显示不就可以了。为什么非要和properties撤上关系呢?
      

  2.   

    不是显示文章。 是将 此字串转为另一个数据库中的字段。
    <资源>  <资源卷次> <年鉴类别>   <标题>  <正文>  分别为要写入别一个数据库的中每个字段
      

  3.   

    其实就是流的操作
    如:
        String s = "a=aaaa\r\nb=bbbb\r\nc=cccc";
        try {
          Properties pt = new Properties();
          pt.load(new StringBufferInputStream(s));
          System.out.println(pt.getProperty("a"));
          System.out.println(pt.getProperty("b"));      
          System.out.println(pt.getProperty("c"));
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      

  4.   

    Properties类的load方法需要一个inputStream作为参数,你只需要将String用相应的InputStream wrap一下就可以了,基本上如 kingfish(八百里秦川@龙城异客)所说!只不过,StringBufferInputStream类已经Deprecated了!
      

  5.   

    下面的例子不论是什么类型文件名都可以,只要是文件内容格式是
    <资源>=上海统计年鉴
    <资源卷次>=2002
    <年鉴类别>=A
    <标题>=编者说明

    每一行对应一个key和value,和*.properties的文件内容一样格式Properties properties = new Properties();
    File file = new File(filename);
    BufferedReader bufReader = new BufferedReader(new FileReader(file));
    //分析数据
    String first = null;
    while ((first = processor.readLine()) != null) {
        index = first.indexOf("=");
        if (index <= 0) continue;
        properties.setProperty(first.substring(0, index), first.substring(index + 1, first.length()));
    }
      

  6.   

    其实从Property文件读取信息,尤其是配置信息还是用得很多,很多时候也是很方便的。我也举个例子吧。
      

  7.   

    File file = new File(filename);
    BufferedReader bufReader = new BufferedReader(new FileReader(file));
    String first;
    Properties properties = new Properties();
    while ((frist = bufReader.readLine()) != null) {
        index = first.indexOf("=");
        if (index <= 0) continue;
        properties.setProperty(first.substring(0, index), first.substring(index + 1, first.length()));
    }
      

  8.   

    考虑到中文和deprecated问题,
    建议用ByteArrayInputStream
      

  9.   

    一般的Property文件的格式都是 什么什么=什么什么,注释行以"#"开头,比如:#这是一个props文件例子(test.props)
    username=jk3278jk
    password=xxxxxxxx
    #用户类型
    usertype=admin
    #部门
    department=sales然后在程序中:
    Properties p = new Properties();
    try {
      p.load(new FileInputStream("test.props"));
    } catch(IOException ioe) {}
    String username = p.getProperty("username");
    String password = p.getProperty("password");
    String usertype = p.getProperty("usertype");
    String department = p.getProperty("department");基本上根楼上说的差不多。
      

  10.   

    Properties类的load方法接受的是InputStream,所以要把String作为Properties文件来进行load的话可以在这里想想办法,把String转换成InputStream或者其子类。
      

  11.   

    关键就是如何把string 转成 inputStream? ??知道吗?
      

  12.   

    以前有一个StringBufferInputStream,不过已经deprecated了。再找找。
      

  13.   

    如果是英文的,直接用ByteArrayInputStream也可以,中文还需要多做点工作。