① 用java编写一个打开指定文件的程序
运行以下代码试试看。
public static void main(String[] args) {
Frame frame = new Frame("打开文件窗口");
frame.setLayout(new FlowLayout(FlowLayout.CENTER));
frame.setBounds(100, 200, 400, 300);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
final TextField txtField = new TextField(50);
Button button = new Button("打开指定文件");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String path = txtField.getText();
System.out.println(path);
if (path.length() == 0) {
return;
}
try {
Runtime.getRuntime().exec("explorer.exe /n, " + path);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
frame.add(txtField);
frame.add(button);
frame.setVisible(true);
}
② java 中怎样实现一个按钮第一次点击后打开文件(指定的),第二次点击后最小化该文件
两个思路
做两个按钮,两个功能分别写在两个按钮上,点击其中一个控制另一个的现实与隐藏
做一个标志位纪录点击次数,根据次数奇偶数,或者其它条件控制执行内容.
③ Java中怎样制作一个按钮用以打开文件
if(obj==button1){
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(frame);
if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
}
}
把这个放在事件处理的 actionPerform()方法中
button1就是你添加的按钮
这样当你点击button1的时候就会显示文件选择窗口
file就是你选择的文件的File对象 你可以进行操作了
④ 怎么用java代码打开txt文件
runtime.exec(...);
sample:
command-line
:
texteditor.exe
"\pub\help.txt"
意思是:通过命令行运行名为
texteditor.exe
程序,并在启动这个程序时候通过命令行参数传递一个将要被打开的名为help.txt
的文件
途径二:用
textarea
装载文本内容显示
⑤ 怎么打开java文件
可以使用JRE
(Java
Runtime
Enviroment)打开:
STEP1:将jad.exe拷贝到JRE的bin目录下,如\Java\jre1.5.0_06\bin
STEP2:配置好你系统的JAVA环境,也就是在PATH里添加你的JRE的路径什么的...(这个还不懂??上GOOGLE去所搜一下,大把大把的)
STEP3:打开命令行,将目录切换到你想要破解的.class文件的目录.例如:我想要破解一个名为example.class的文件,它在e:\workspaces\里,那我就输入cd
e:\workspaces\让后回车.开始"脱"啦!:
反编译单个JAVA语言的CLASS文件,在命令行输入:jad
example.class回车.
让后在你当前目录会生成一个Example.jad的文件!把它的后缀改为java就可以阅读了!(你可以忽略.class后缀)
选项
-s<后缀>允许你更改输出文件的后缀.
jad
-sjava
example.class
这条命令生成文件'example.java'.当你同时使用选项-o和-sjava时要小心了,因为Jad会意外的覆盖掉你的源文件.jad使用JAVA的CLASS文件名作为默认的输出文件名.举个例子,如果CLASS文件'example.class'包含了JAVA的CLASS'test'那么jad会优先生成'test.jad'.如果你想要指定一自己的输出文件名,请使用重定向:
jad
-p
example.class
>myexm.java选项-d允许你指定输出文件到另外一个文件夹,这个文件夹将默认创建在当前目录.举个例子:
jad
-o
-dtest
-sjava
*.class
(或者jad
-o
-d
test
-s
java
*.class,两者是一样的)
这条命令反编译所有.class文件在当前目录并且放置所有输出文件在目录'test'以.java为后缀名.如果你想反编译整个java类树,用如下命令:
jad
-o
-r
-sjava
-dsrc
tree/**/*.class
这条命令反编译所有.class文件位于'tree'以及子目录并且建立输出文件在'src'目录的相对子目录中依照类的包名.举个例子,如果文件'tree/a/b/c.class'包含类'c'来自包'a.b',那么数车文件的名字是'src/a/b/c.java'.万一你想要检查输出文件的精确度或者就是仅仅是好奇,这儿有个选项-a,它让jad使用JAVA虚拟机字节码作为注释添加在输出文件中.jad支持内部类和匿名类,当jad把通配符搭配到输入的文件名时,它自动的跳过匹配的内部类.在UNIX系统中jad跳过内部类如果有多于一个类在命令行中指定了.
JRE官方下载地址:
http://java.sun.com/javase/downloads/index.jsp
⑥ 在java中使用什么代码,可以使按钮具有打开目标文件夹的功能
打开文件
//打开工具的路径及名字
String toolsPath = "C:/WINDOWS/system32/notepad.exe ";
//被打开文件的路径及名字
String fileName = "test.txt";
try {
Runtime.getRuntime().exec(toolsPath+fileName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
打开文件夹
try {
String[] cmd = new String[5];
String url = "C:/input";
cmd[0] = "cmd";
cmd[1] = "/c";
cmd[2] = "start";
cmd[3] = " ";
cmd[4] = url;
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
或者
Runtime.getRuntime().exec("cmd /c start C:/input");
希望采纳
⑦ JAVA 如何通过按钮打开另一个程序
package kuohao;
import java.awt.Button;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class jtxtfm {
public static void main(String args[]) {
JFrame jf = new JFrame();
JPanel jp = new JPanel();
JButton jb = new JButton("打开对话框");
jf.add(jp);
jp.add(jb);
jf.setVisible(true);
jf.setSize(200,200);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jtxtfrm fm = new jtxtfrm();
}
});
}
}
class jtxtfrm extends Frame implements ActionListener {
FileDialog op, sv;
Button btn1, btn2, btn3;
TextArea tarea;
jtxtfrm() {
super("读写文件");
setLayout(null);
setBackground(Color.cyan);
setSize(600, 300);
setVisible(true);
btn1 = new Button("打开");
btn2 = new Button("保存");
btn3 = new Button("关闭");
tarea = new TextArea("");
add(btn1);
add(btn2);
add(btn3);
add(tarea);
tarea.setBounds(30, 50, 460, 220);
btn1.setBounds(520, 60, 50, 30);
btn2.setBounds(520, 120, 50, 30);
btn3.setBounds(520, 180, 50, 30);
op = new FileDialog(this, "打开", FileDialog.LOAD);
sv = new FileDialog(this, "保存", FileDialog.SAVE);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
String str;
op.setVisible(true);
try {
File f1 = new File(op.getDirectory(), op.getFile());
FileReader fr = new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
tarea.setText("");
while ((str = br.readLine()) != null)
tarea.append(str + '\n');
fr.close();
} catch (Exception e1) {
}
}
if (e.getSource() == btn2) {
sv.setVisible(true);
try {
File f1 = new File(sv.getDirectory(), sv.getFile());
FileWriter fw = new FileWriter(f1);
BufferedWriter bw = new BufferedWriter(fw);
String gt = tarea.getText();
bw.write(gt, 0, gt.length());
bw.flush();
fw.close();
} catch (Exception e2) {
}
}
if (e.getSource() == btn3) {
System.exit(0);
}
}
}
只要将你的代码写在button下的监听里面就可以了,你看一下我的这个代码,只是做了个简单的改动,就实现了
⑧ java怎么实现一点击按钮,就打开一个共享文件夹
用java执行cmd命令就行了。
Runtime rt = Runtime.getRuntime();
rt.exec("explorer.exe c://windows");
事件自己加就行了
⑨ java用JButton怎么打开一个txt文件
使用文件流来打开和读取文件的.在按钮组件中添加相应的事件处理就行了,以下是示例:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class TestViewer extends JFrame implements ActionListener{
private JTextArea text;
private JScrollPane pane;
private JButton button;
public TestViewer(){
super("TextViewer");
text=new JTextArea();
text.setEditable(false);
text.setLineWrap(true);
pane=new JScrollPane(text);
getContentPane().add(pane,BorderLayout.CENTER);
getContentPane().add(button,BorderLayout.BOTTOM);
button.addActionListener(this);
setSize(400,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
JFileChooser fc=new JFileChooser();
char ch[]=new char[1024];
String str="",s="";
fc.showOpenDialog(this);
try{
FileReader fr=new FileReader(fc.getSelectedFile());
while(fr.read(ch)!=-1){
s=new String(ch);
str=str+s;
}
text.setText(str);
fr.close();
}catch(IOException ie){
JOptionPane.showMessageDialog(this,"I/O Error","error",JOptionPane.ERROR_MESSAGE);
}
}else{
System.exit(0);
}
}
public static void main(String args[]){
TestViewer tv=new TestViewer();
}
}
⑩ JAVA程序中点击按钮打开文件对话框
1.打开文件
Dim clsIntCmn As New WxsIntCmn
Dim strpath As String = txtPath.Text
clsIntCmn.Openfile(strpath, Page)
System.Diagnostics.Process.Start(strpath)
2.上传文件
Public Function Savefile(ByVal strFilepath As String, ByVal Request As HttpFileCollection) As Boolean
Dim bolflag As Boolean = True
Dim uploadedFiles As HttpFileCollection = Request
For i As Integer = 0 To uploadedFiles.Count - 1
Dim userPostedFile As HttpPostedFile = uploadedFiles(i)
Try
'要保存文件的路径
Dim strPath As String = strFilepath & "\" & _
System.IO.Path.GetFileName(userPostedFile.FileName)
If (userPostedFile.ContentLength > 0) Then
'保存文件
userPostedFile.SaveAs(strPath)
End If
txtPath.Text = strPath
txtDelPath.Text = strPath
Catch ex As Exception
bolflag = False
i = uploadedFiles.Count
End Try
Next
Return bolflag
End Function
这是我曾经写过的,也已经用过,试试吧!应该可以帮助你的,不过你要改用一下语言