① 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();