0

我正在用 Java 编写一个函数来逐行读取 PHP。我注意到有些行被跳过了。

Java中的函数:

 public String ReadContentRegex(String path, String Regex) throws
 FileNotFoundException, IOException
     {
         final StringBuilder contents = new StringBuilder();

         BufferedReader br = new BufferedReader(

         new InputStreamReader(new FileInputStream(path)));

         try {
             String line;

             while ((line = br.readLine()) != null) {
                 System.out.println(br.readLine());

             }
         } finally {
             br.close();
         }

         return contents.toString();

     }

Java 应该使用的 PHP 文件BufferedReader

<?php #if (!APP_ACT) exit();

class dbtest extends Codeplexon\core\fwcontroller {

public $name = __CLASS__;

    static function destruct()
{
    // ili 404
    echo("Error function: ".__FUNCTION__);
}

public function db()
{       
        $model = new Codeplexon\model\fwmodel;
        $model->db->load();
        #$e = $model->db->count();
        $model->db->select();
        $model->db->from("db");
        $model->db->query();
        $a = $model->db->fetch();
        #$num_rows = $model->db->numrows();
        #$lastquery = $model->db->lastquery();

        var_dump($a);
}
    //etc....

输出错误:

class dbtest extends Codeplexon\core\fwcontroller {

        // ili 404

            $model = new Codeplexon\model\fwmodel;
            $model->db->select();
            $a = $model->db->fetch();


            $model = new Codeplexon\model\fwmodel;
            $obj = array("val" => substr(md5(time()), 0, 10));
        }
        {
            $model->db->load();
            $model->db->where("id", "5");

            $model = new Codeplexon\model\fwmodel;
            $r = $model->db->querycustom('SELECT * FROM a_mvcdb.db WHERE id = 4');

        }
        {

.toString()我认为 return 语句或类名有问题,public String ReadContentRegex(String path, String Regex)但我不确定出了什么问题。

4

1 回答 1

5

你打readLine()了两次电话。

您读取一行并将其存储在 String 变量中line

while ((line = br.readLine()) != null) {

然后你忽略你读的内容,你在你的 println 语句中读了另一行。

System.out.println(br.readLine());

将上面的行更改为

System.out.println(line);
于 2013-07-03T16:54:19.143 回答