导航:首页 > 编程语言 > java打开本地文件

java打开本地文件

发布时间:2022-08-08 16:19:32

java 打开本地文件

你是要把里面的内容读出来?

package nb;

import java.io.*;

public class InputPic
{
public static void main(String args[]) throws Exception
{
String ppath=args[0];
File file=new File(ppath);
byte[] data=new byte[(int)file.length()];

FileInputStream fin=new FileInputStream(file);
fin.read(data);
fin.close();

}
}

② 怎样用java打开指定文件

File file = new File("文件绝对路径");
Desktop.getDesktop().open(file);
即可调用系统的默认打开工具,打开这个文件

③ Java 浏览本地硬盘文件

只是获取某个路径下的文件夹
可以用File里面的listFiles() 方法获取到该路径下的所有File对象的数组引用
如果想用类似于windows中的打开、保存那样的对话框可以调用
JFileChooser类

④ 如何用java打开一个本地文件

上代码

String[]cmd=newString[]{
"cmd.exe",
"/c",
//第三个参数就是你要打开的文件路径
"D:\Work\workspace\GIFRecorder.rar"
};
Runtime.getRuntime().exec(cmd);

⑤ Java打开指定文件

java打开文件夹使用方法:
String strTmp= "D:\abc\";
Runtime.getRuntime().exec("explorer.exe" + strTmp);
java读取文件使用方法:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class OpenFile {
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new FileReader("c://EmailSpider.java"));
String line = "";
while((line=br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

⑥ 现在有个java程序。。需要打开本地文件。。弹出一个窗口。。

我猜你应该是用了一个JFileChooser对象吧,其中有一个方法叫changeToParentDirectory()方法,该方法会将目录调整到当前目录的父目录,比如说C盘或者D盘,另外还有一个方法叫setCurrentDirectory(File file)方法,这个方法可以直接指定当前目录应该从哪开始。
JFileChooser choose = new JFileChooser();
// 使用父目录
choose.changeToParentDirectory();
choose.showOpenDialog(null);
//使用指定目录
choose.setCurrentDirectory(new File("D:/Java"));
choose.showOpenDialog(null);
希望能帮到您。
引用连接:http://..com/question/413947089.html

⑦ 如何使一个java程序,一执行,就打开本地某目录下的html文件比如abc.html, 就像双击打开那样!

如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样!15

public static void main(String args[]) throws Exception
{
File file = new File("abc.html");
Runtime ce=Runtime.getRuntime();
System.out.println(file.getAbsolutePath());
ce.exec(file.getAbsolutePath());
}

像这样,想打开同目录下的abc.html,怎么不行呢?



恩,你的命令不正确,怎么会打开呢?
试试我给你的代码吧
import java.io.File;
public class TestRuntime {

/**
* @param args
*/
public static void main(String args[]) throws Exception
{
File file = new File("abc.html");
Runtime ce=Runtime.getRuntime();
System.out.println(file.getAbsolutePath());
ce.exec("cmd /c start "+file.getAbsolutePath());
}
}

只要在你的同目录下有abc.html,就可以打开了

⑧ java代码中打开文件

如果你只想实现,就像双击了电脑某个文件
让系统用其它应用去打开这个文件的话
可以用这个:
java.awt.Desktop.getDesktop().open(file);

⑨ 用java 读取本地磁盘下的一个txt文件

importjava.io.BufferedInputStream;
importjava.io.FileInputStream;
importjava.io.IOException;

{
publicstaticvoidmain(String[]args)throwsIOException{
//BufferedInputStream(InputStreamin)
BufferedInputStreambis=newBufferedInputStream(newFileInputStream(
"bos.txt"));

//读取数据
//intby=0;
//while((by=bis.read())!=-1){
//System.out.print((char)by);
//}
//System.out.println("---------");

byte[]bys=newbyte[1024];
intlen=0;
while((len=bis.read(bys))!=-1){
System.out.print(newString(bys,0,len));
}

//释放资源
bis.close();
}
}

⑩ java怎样读取本地文件夹下的文件

Filefile=newFile("WebRoot\test.html");
BufferedReaderbufferedReader=
newBufferedReader(newInputStreamReader(newFileInputStream(file)));
Stringrow=null;
StringBuffersb=newStringBuffer();
while((row=bufferedReader.readLine())!=null){
System.out.println(row);
sb.append(row);
}
bufferedReader.close();

阅读全文

与java打开本地文件相关的资料

热点内容
叫别人做商城有源码吗 浏览:907
无所不能的程序员是谁呀 浏览:142
清理文件加密软件 浏览:67
瘦吧大数据在APP哪里看 浏览:623
层次聚类算法最小距离 浏览:696
抖音视频加源码 浏览:534
运营影视源码 浏览:643
北京电信服务器托管云空间服务器 浏览:371
一般学编程有必要吗 浏览:755
机器人编程方法 浏览:992
表盘编程gt 浏览:9
java源代码阅读 浏览:736
程序员用什么键盘罗技 浏览:169
为什么安卓手机每天都要更新app 浏览:707
java怎么成为程序员 浏览:290
西门子s7200编程电缆怎么连接 浏览:532
下载网页中的pdf文件 浏览:91
音乐缓存文件夹的软件 浏览:396
Dkms编译打印机驱动 浏览:996
解压缩文件操作异常 浏览:557