java读取txt文件中的内容,在线等 calsslist.txt文件中,有些内容,现如何在java代码中用system.out.println 输出来,在线等 thanks 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** * @param args */ public static void main(String[] args) { try { InputStream is = new FileInputStream("F:/测试.txt"); byte[] buffer = new byte[1024 * 10]; while (is.read(buffer) != -1) { System.out.println(new String(buffer,"utf-8")); } } catch (Exception e) { e.printStackTrace(); } } java文件和calsslist.txt在同一目录中,现如何在java代码中用system.out.println 把txt文件中内容 输出来,thanks 用GBK试试,System.out.println(new String(buffer,"gbk")); 没有问题 我测试过了提醒下:必须是java工程,android工程不行 多谢大家txt和java文件在同一目录下,都在src下 file = new FileInputStream("classlist.txt"); System.out.println("f1"+file);为什么这个file 打印出来会为空呢,thanks 回7楼的,是在android项目中。。 不知道你描述是否正确?如果像你所说的,肯定不行你用的相对路径,相对的是整个项目所以你的txt文件应该放在项目根目录,而不是src下 再次提醒,android工程中main方法执行是不会输出东西的 路径不对,可以使用\sdcard\你的文件 方式访问 路径不对,可以使用\sdcard\你的文件 方式访问这是我的群222164346,欢迎加入,谢谢! 把classlist放在asset文件夹,在读。 file = this.getResources().getAssets().open("classlist.txt"); System.out.println("f1"+file); BufferedReader br=new BufferedReader(new InputStreamReader(file)); show=br.readLine(); while(br.readLine()!=null){ show=show+br.readLine(); } } catch (Exception e1) { e1.printStackTrace(); } //System.out.println(show+"^^^^^^^^^^^^"); android 使用外部数据库问题 关于android生命周期遇到的问题,求解!! FragmentActivity 在切换 Fragment时触发什么事件 android客户端传图片问题 大家做android开发时,包组织结构一般是什么? 关于context 关于更新sdk和adt到22.6后新建项目中layout文件夹下有activity_main.xml和fragment_main.xml的问题 Android通讯录 调用.os文件中的方法出现method not found,该如何解决呢? 多张图片分享 android 怎样彻底删除联系人 Android求助
/**
* @param args
*/
public static void main(String[] args) {
try {
InputStream is = new FileInputStream("F:/测试.txt");
byte[] buffer = new byte[1024 * 10];
while (is.read(buffer) != -1) {
System.out.println(new String(buffer,"utf-8"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
现如何在java代码中用system.out.println 把txt文件中内容 输出来,thanks
提醒下:必须是java工程,android工程不行
txt和java文件在同一目录下,都在src下 file = new FileInputStream("classlist.txt");
System.out.println("f1"+file);为什么这个file 打印出来会为空呢,
thanks
如果像你所说的,肯定不行
你用的相对路径,相对的是整个项目
所以你的txt文件应该放在项目根目录,而不是src下
路径不对,可以使用\sdcard\你的文件 方式访问这是我的群222164346,欢迎加入,谢谢!
System.out.println("f1"+file);
BufferedReader br=new BufferedReader(new InputStreamReader(file));
show=br.readLine();
while(br.readLine()!=null){
show=show+br.readLine();
}
} catch (Exception e1) {
e1.printStackTrace();
}
//System.out.println(show+"^^^^^^^^^^^^");