假如获得一个输入流,有什么方法可以得到这个输入流数据来源的路径啊?
------解决方案--------------------
范围比较大,我给段代码参考
创建txt,写入字符:
File file = new FIle("test.txt");
FileOutputStream out = new FileOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out, "utf-8");
BufferedWriter bw = new BufferedWriter(writer);
bw .write("今天是什么日子?");
bw.newLine();
bw.write("2010年啊");
bw.flush;
bw.close;
从txt中读取字符:
FileInputStream in = new FileInputStream(new File("test.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
String line = null;
while((line=br.readLine()) != null){
System.out.println(line);
}
br.close;
------解决方案--------------------
一般得不到,而且未必有路径,说不定是程序产生的源?或者键盘输入的源?
------解决方案--------------------