java.net.malformedurlexception未知协议D [英] java.net.malformedurlexception unknown protocol D
本文介绍了java.net.malformedurlexception未知协议D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我正在尝试读取文本文件,但出现此错误:java.net.malformedurlexception未知协议D ..而我的代码是
hi friends i am trying to read a text file and i am getting this error: java.net.malformedurlexception unknown protocol D.. and my code is
public class AndroidInternetTxt extends Activity {
TextView textMsg;
TextView textPrompt;
//private ContextWrapper context;
//private String fileName;
//String filePath = context.getFilesDir().getAbsolutePath();//returns current directory.
//File file = new File(filePath, fileName);
final String textSource = "D:/text.txt";
//http://sites.google.com/site/androidersite/text.txt
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textPrompt = (TextView) findViewById(R.id.textprompt);
textMsg = (TextView) findViewById(R.id.textmsg);
textPrompt.setText("Wait...");
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
textPrompt.setText("Finished!");
}
}
上面的代码中有什么问题
what is wrong in the above code
推荐答案
尝试final String textSource = "file:///D:/text.txt";
这篇关于java.net.malformedurlexception未知协议D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文