主题:新手求教!文本URL转换,有那位高手能帮忙指教一下错在那,谢谢!
package myshitu;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
public class view3 extends ViewPart
{
public void createPartControl(Composite parent)
{
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new GridLayout());
Label label = new Label(topComp, SWT.NONE);
GridData griddata = new GridData(GridData.FILL_HORIZONTAL);
griddata.horizontalAlignment = GridData.CENTER;
label.setText("显示选项3");
label.setLayoutData(griddata);
final Text text = new Text(topComp, SWT.BORDER);
GridData griddata1 = new GridData(GridData.FILL_HORIZONTAL);
griddata.horizontalAlignment = GridData.BEGINNING;
text.setLayoutData(griddata1);
text.setText("http://c:/eAladdinLog.txt");
Button bt = new Button(topComp, SWT.NONE);
bt.setText("显示");
final Text text1 = new Text(topComp, SWT.BORDER);
GridData griddata2 = new GridData(GridData.FILL_BOTH);
griddata.horizontalAlignment = GridData.BEGINNING;
text1.setLayoutData(griddata2);
bt.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent ex)
{
try
{
URL url = new URL("c:/eAladdinLog.txt");
URI uri = url.toURI();
File f1 = new File(uri);
FileInputStream is = new FileInputStream(f1);
byte[] buff = new byte[1000];
is.read(buff,0,1000);
String sb=buff.toString();
//String sb = new String(buff, 0, len);
text1.setText(sb);
is.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
public void setFocus()
{
}
}
程序是插件中的一个显示窗体
但是显示不了URL指定文本!
有那位高手能帮忙指教一下错在那,谢谢!
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
public class view3 extends ViewPart
{
public void createPartControl(Composite parent)
{
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new GridLayout());
Label label = new Label(topComp, SWT.NONE);
GridData griddata = new GridData(GridData.FILL_HORIZONTAL);
griddata.horizontalAlignment = GridData.CENTER;
label.setText("显示选项3");
label.setLayoutData(griddata);
final Text text = new Text(topComp, SWT.BORDER);
GridData griddata1 = new GridData(GridData.FILL_HORIZONTAL);
griddata.horizontalAlignment = GridData.BEGINNING;
text.setLayoutData(griddata1);
text.setText("http://c:/eAladdinLog.txt");
Button bt = new Button(topComp, SWT.NONE);
bt.setText("显示");
final Text text1 = new Text(topComp, SWT.BORDER);
GridData griddata2 = new GridData(GridData.FILL_BOTH);
griddata.horizontalAlignment = GridData.BEGINNING;
text1.setLayoutData(griddata2);
bt.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent ex)
{
try
{
URL url = new URL("c:/eAladdinLog.txt");
URI uri = url.toURI();
File f1 = new File(uri);
FileInputStream is = new FileInputStream(f1);
byte[] buff = new byte[1000];
is.read(buff,0,1000);
String sb=buff.toString();
//String sb = new String(buff, 0, len);
text1.setText(sb);
is.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
public void setFocus()
{
}
}
程序是插件中的一个显示窗体
但是显示不了URL指定文本!
有那位高手能帮忙指教一下错在那,谢谢!