Click here to Skip to main content
15,917,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Java
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
Posted
Updated 23-Sep-11 20:22pm
v2
Comments
DaveAuld 24-Sep-11 10:27am    
Is the exception being thrown by this line by any chance? textUrl = new URL(textSource);

1 solution

Try final String textSource = "file:///D:/text.txt";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900