「java点击按钮打开文件」java点击按钮打开文件不显示

博主:adminadmin 2022-12-11 12:09:07 68

本篇文章给大家谈谈java点击按钮打开文件,以及java点击按钮打开文件不显示对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Java应用程序怎样点击按钮弹出文件查找路径的窗口

1、js弹出文件选择框:

给按钮定义以下javascript函数:

var inputObj=document.createElement('input')

inputObj.setAttribute('id','_ef');

inputObj.setAttribute('type','file');

inputObj.setAttribute("style",'visibility:hidden');

document.body.appendChild(inputObj);

inputObj.click();

inputObj.value ;

单击已经添加函数的按钮会弹出选择本地文件的对话框。

2、写一个隐藏域, 当用户选择文件之后把图片的路径赋给这个隐藏域, 然后在action中就可以获取到文件的路径了,代码如下:

function showRealPath(filePath){

document.getElementsByName("textfield")[0].value = filePath;

}

input type="file" name="uploadfile" onfocus="showRealPath(this.value);"/

input type="hidden" name="uploadfileRealPath"

java怎么实现一点击按钮,就打开一个共享文件夹

用java执行cmd命令就行了。

Runtime rt = Runtime.getRuntime();

rt.exec("explorer.exe c://windows");

事件自己加就行了

java 中怎样实现一个按钮第一次点击后打开文件(指定的),第二次点击后最小化该文件

两个思路

做两个按钮,两个功能分别写在两个按钮上,点击其中一个控制另一个的现实与隐藏

做一个标志位纪录点击次数,根据次数奇偶数,或者其它条件控制执行内容.

Java中怎样制作一个按钮用以打开文件?

//费了我一会功夫给你编了个读取文件的程序,你看看是不是你想要的,我这有个java学习讨论群(77077753),你可以加入,有什么问题可以在群里讨论!!

import java.awt.*;

import java.io.*;

import java.awt.event.*;

public class wenjian

extends Frame

implements ActionListener {

FileDialog open = new FileDialog(this, "打开文件",

FileDialog.LOAD);

String fileName;

Button b_dakai = new Button("打开");

TextArea text = new TextArea();

wenjian() {

super("文件的打开");

setBounds(400, 200, 400, 300);

b_dakai.addActionListener(this);

add(text);

add(b_dakai, "South");

setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == b_dakai) {

open.show();

fileName = open.getDirectory() + open.getFile();

if (fileName != null) {

readFile(fileName);

}

}

}

// 这是一个打开文件文件的方法

public void readFile(String fileName) {

try {

File file = new File(fileName);

FileReader readIn = new FileReader(file);

int size = (int) file.length();

int charsRead = 0;

char[] content = new char[size];

while (readIn.ready()) {

charsRead += readIn.read(content, charsRead, size - charsRead);

}

readIn.close();

text.setText(new String(content, 0, charsRead));

}

catch (IOException e) {

System.out.println("Error Opening file");

}

}

public static void main(String args[]) {

new wenjian().addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

};

});

;

}

}

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

这是我曾经写过的,也已经用过,试试吧!应该可以帮助你的,不过你要改用一下语言

java点击按钮打开文件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java点击按钮打开文件不显示、java点击按钮打开文件的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-11,除非注明,否则均为首码项目网原创文章,转载请注明出处。