Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to read a text file programmatically inside Eclipse?
How to read a text file programmatically inside Eclipse? [message #289156] Sun, 31 July 2005 04:53 Go to next message
Eclipse UserFriend
Originally posted by: morphobit.freakmail.de

Hi everybody,
I'm trying to open a simple text file in eclipse in order to create a
String out of the file content and I'm not getting it to work.

I tried the following:

String textFile = "testproject/test.txt"
IPath textFileIPath = new Path ( textFileFile );
String textFileLocation =
ResourcesPlugin.getWorkspace().getRoot().findMember( textFileIPath
).getLocation().toString();
URI queryFileURI = URI.createFileURI( textFileLocation );
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource( textFileURI );
resource.load( Collections.EMPTY_MAP );

Any help is appreciated!

Thanks,
Hans
Re: How to read a text file programmatically inside Eclipse? [message #289164 is a reply to message #289156] Mon, 01 August 2005 04:05 Go to previous message
Eclipse UserFriend
Hi
I suppose you try to read it from your plugin,
with your "test.txt" bundled within the plugin jar.

To read you can use something like openMyTestStream("test.txt");
with :
private InputStream openMyTestStream(String filename) {
try {
URL installURL = MyPlugin.getDefault().getBundle().getEntry("/");
URL url = new URL(installURL, filename);
return ( url.openStream() );
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

HTH
Rémi

Hans Meier a écrit :
> Hi everybody,
> I'm trying to open a simple text file in eclipse in order to create a
> String out of the file content and I'm not getting it to work.
>
> I tried the following:
>
> String textFile = "testproject/test.txt"
> IPath textFileIPath = new Path ( textFileFile );
> String textFileLocation =
> ResourcesPlugin.getWorkspace().getRoot().findMember( textFileIPath ).getLocation().toString();
> URI queryFileURI = URI.createFileURI( textFileLocation );
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.createResource( textFileURI );
> resource.load( Collections.EMPTY_MAP );
>
> Any help is appreciated!
>
> Thanks,
> Hans
Previous Topic:Throwing multiple exceptions
Next Topic:Help Debuging Swing JScrollpane
Goto Forum:
  


Current Time: Thu May 08 09:46:04 EDT 2025

Powered by FUDForum. Page generated in 0.08213 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top