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+"^^^^^^^^^^^^"); 关于setting的string.xml里的product属性的问题 AlertDialog.Builder回调问题 android SDK自带的图标文件在哪里? ndk activity launch timeout 真心求解惑 android 错误2 android代码问题:public SpeakContact getContact(long id) 关于android开发用viewflipper实现滑屏问题 手机短信如何加入像网页段的超链接 问一下,这个表白代码,怎么改里面的名字?谢谢了!! 请问使用webView的APP问题 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+"^^^^^^^^^^^^");