導航:首頁 > 編程語言 > 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打開本地文件相關的資料

熱點內容
網店美工pdf 瀏覽:445
一堆文件夾怎麼弄出來 瀏覽:743
博途如何編譯硬體 瀏覽:418
fortran程序pdf 瀏覽:504
電池消耗演算法 瀏覽:394
伺服器中斷連接怎麼處理 瀏覽:222
上世紀互聯網不發達程序員很難 瀏覽:841
語音識別android開源 瀏覽:762
地埋式垃圾壓縮中轉站 瀏覽:902
apachehttpdlinux 瀏覽:944
快遞員中通app預付款是什麼 瀏覽:843
java路徑轉義 瀏覽:857
keytool加密演算法 瀏覽:131
笑臉圖案的APP相機是什麼軟體 瀏覽:249
app軟體為什麼會被下架 瀏覽:981
從內存到硬碟的命令是 瀏覽:52
程序員的爸爸們的發型 瀏覽:123
魔獸世界傷害壓縮是怎麼壓的 瀏覽:976
壓縮機型號hp 瀏覽:959
配音虛弱的程序員 瀏覽:61