栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【Java】Incompatible operand types char and String

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Java】Incompatible operand types char and String

请只看加粗斜体的代码

	public static String txt(File file) {
		int lineHeight=0;
		***char ch;***
		StringBuilder result =new StringBuilder();
		try {//构造一个BufferedReader类来读取文件
			***BufferedReader br=new BufferedReader(new FileReader(file));***
			String a = null;
			while( (a=br.readLine())!=null ) {//使用readLine方法,一次读一行
				lineHeight++;
				String a1=a.toLowerCase();
				String a2=a1.replace(" ", "");
				result.append(System.lineSeparator()+a2); //变小写,去空格
				***ch = result.charAt(0);*** 
				***if( ch=='#' ) break;*** **//该行出错,最初代码为:if( ch=="#" ) break;**

			}	
			br.close();
		}catch(Exception e) {
			e.printStackTrace();
		}
		return result.toString();
	}

修改方法:

String方法charAt()返回的是字符,而不是字符串,应该用单引号,而不是双引号。

参考文章:
http://bbs.itheima.com/thread-110043-1-1.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/644405.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号