java读取txt 保留原来格式(空行,空格。。。)
publicstaticStringgetRuleByTxt(){StringtheRule="";try{BufferedReaderin=newBufferedRea...
public static String getRuleByTxt()
{
String theRule = "";
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("gobangrule.txt ")), "gb2312"));
String line = null;
while((line = in.readLine())!=null)
{
theRule = theRule + line;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return theRule;
}
这段代码读取的txt返回然后打印就没有空行,貌似也没段落前后的空格了。
求解!!! 展开
{
String theRule = "";
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("gobangrule.txt ")), "gb2312"));
String line = null;
while((line = in.readLine())!=null)
{
theRule = theRule + line;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return theRule;
}
这段代码读取的txt返回然后打印就没有空行,貌似也没段落前后的空格了。
求解!!! 展开
1个回答
展开全部
theRule = theRule + line + "\r\n";
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |