67,513
社区成员
发帖
与我相关
我的任务
分享
public String getArticleContent(String path)
{
File file = new File(path);
String read = "";
StringBuilder sb = new StringBuilder();
InputStreamReader isr = null;
BufferedReader br = null;
try
{
isr = new InputStreamReader(new FileInputStream(file));
br = new BufferedReader(isr);
while ((read = br.readLine()) != null)
{
sb.append(read + "\n");
}
} catch (Exception e)
{
} finally
{
if (br != null)
{
try
{
br.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
if (isr != null)
{
try
{
isr.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
return sb.toString();
}
if (res != null)
{
if (res.next())
{
title = res.getString("title");
content = getArticleContent(res
.getString("article_content"));
list.add(new ArticleBean(title, content));
System.out.println("文章路径----->>>"
+ res.getString("article_content"));
System.out.println(content);
} else
{
list.add(new ArticleBean("没有文章", null));
}
}
File f = new File("testFilePath.txt");
if(!f.exists())
{
f.createNewFile();
}
是可以直接在工程目录下创建一个文件的。
当然,最安全的获取工程目录的方法,是使用System.getProperty("user.dir")获取。这样,可以以工程目录为基准,可以操作当前目录(./实现)或上级目录(../实现),查找目标文件和文件夹。