试试FileInputStream("./new.txt");

解决方案 »

  1.   

    FileInputStream(context.getRealPath("/yourdir/new.txt"))
      

  2.   

    还是找不到啊JSP文件 C:\Tomcat\webapps\ROOT\newtest.jspnew.txt文件 C:\Tomcat\webapps\ROOT\new.txt
      

  3.   

    new.txt放到根目录
    FileInputStream("/new.txt");
      

  4.   

    public void addClob() {
    try {
    //取得旧表得ID列表
    // ResultSet rsTmp=DoSQL.Select("zd2_T_NEWS2","COL007",false);
    //String [] idList = SQLAI.getPrimaryKey("fj_xt_zd2_T_news");
    String[] idList = this.getContent();
    String titleList[] = this.getTitle();
    String newsID [] = this.getNewsID();
    //--开始读取大文本到数据库--
    int countReplain = 0; //统计导入的大文件个数 for (int i = 0; i < idList.length; i++) {
    //--初始化数据库连接--
    java.sql.Connection con = Dbconn.pubGetCon();
    con.setAutoCommit(false);
    java.sql.Statement st = con.createStatement();
    PreparedStatement psSel = null;
    PreparedStatement ps = null;
    ResultSet rs = null; //构造文件名
    String path = "c:\\abc\\" + idList[i].trim() + ".txt";
    //--取得数据库重中的大文本字段--
    int id = i;
    rs = null;
    /* 查询此CLOB对象并锁定 */
    String sql =
    "insert into t_news_message2 (id,title,content) values (?,?,empty_clob())";
    String selectSql =
    "SELECT content FROM t_news_message2 WHERE ID="
    + id
    + " FOR UPDATE";
    String sqlUpdate =
    "update "
    + "t_news_message"
    + " SET content=? where id = "
    + id;
    psSel = con.prepareStatement(sql);
    psSel.setInt(1, id);
    psSel.setString(2, titleList[i]);
    psSel.executeUpdate();
    rs = st.executeQuery(selectSql);
    rs.next();
    CLOB clob = (CLOB) rs.getClob("content");
    //----
    BufferedReader in = null;
    //BufferedWriter out=null;
    try {
    //-- 向CLOB对象中写入数据 --
    //out = new BufferedWriter(clob.getCharacterOutputStream());
    in = new BufferedReader(new FileReader(path));
    if (in != null) {
    String s;
    String sAll = new String("");
    if(this.getCountNewsID(newsID[i])>0)
    {
    sAll = sAll + this.getPicUrl(newsID[i]) ;
    }
    while ((s = in.readLine()) != null) { sAll = sAll + "&nbsp;&nbsp;&nbsp;&nbsp;"+ s + "<br>";
    }
    System.out.println(sAll); clob.putString(1L, sAll);
    ps = con.prepareStatement(sqlUpdate);
    ps.setClob(1, clob);
    ps.executeUpdate();
    //         int writeClob;
    //         while ( (writeClob = in.read()) != -1) {
    //           out.write(writeClob);
    //         }
    countReplain++; //统计目前已经导入的大文本个数
    con.commit();
    con.setAutoCommit(true);
    }
    } catch (Exception e1) {
    System.out.println("Lose file:" + path);
    if (in != null)
    in.close(); //if(out!=null)out.close(); //----
    } if (rs != null)
    rs.close();
    if (st != null)
    st.close();
    if (ps != null)
    ps.close();
    if (psSel != null)
    psSel.close();
    if (con != null)
    con.close();
    //----
    } System.out.println("共有文件" + countReplain);
    } catch (Exception e) {
    } }
      

  5.   

    String path = "c:\\abc\\" + idList[i].trim() + ".txt";