当前位置:首页 » 知网查重 » java读取文件目录

java读取文件目录

发布时间: 2021-03-01 01:09:57

㈠ java如何读取指定目录下的txt文件

你好代码如下,我调试通过了,希望我的回答对你有帮助!

代码说明,要查询是否存在''java"。在D:盘建一个word.txt的文档,里面写一些单词,保存。运行如下代码会判断是否存在“java”这个单词。

packaget;
importjava.io.BufferedReader;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassTestRead{
publicstaticvoidmain(String[]args)throwsIOException{
FileInputStreamfis=newFileInputStream("d:/word.txt");
InputStreamReaderisr=newInputStreamReader(fis);
BufferedReaderbr=newBufferedReader(isr);
Strings;
intcount=0;
while((s=br.readLine())!=null){
String[]s1=s.split("");
for(inti=0;i<s1.length;i++){
if("java".equals(s1[i])){
System.out.println("存在单词"+s1[i]);
count++;
}
}
}
if(count==0){
System.out.println("不存在java这个单词");
}
}
}

㈡ java中在怎么读取文件夹中的内容

以下java程序的作用是将当前目录及其子目录中的.java文件收集到collection.txt文件中,并添加行号,你可以参考一下。
import java.io.*;
public class Collection
{
public static void main(String[] args) throws Exception
{
final String F=".\\collection.txt";

FW=new FileWriter(new File(F));
Collection.ProcessDirectory(new File("."));
Collection.FW.flush();
Collection.FW.close();
}

private static void ProcessDirectory(File d) throws Exception
{
File[] ds=null;

Collection.ProcessJavaFile(d);
ds=d.listFiles(Collection.DFilter);
for(int i=0;i<ds.length;i++)
{
Collection.ProcessDirectory(ds[i]);
}
}

private static void ProcessJavaFile(File d) throws Exception
{
String line=null;
LineNumberReader lnr=null;
File[] fs=d.listFiles(Collection.FNFilter);

for(int i=0;i<fs.length;i++)
{
lnr=new LineNumberReader(new FileReader(fs[i]));
Collection.FW.write(fs[i].getCanonicalPath()+"\r\n");
System.out.println(fs[i].getCanonicalPath());
while(null!=(line=lnr.readLine()))
{
Collection.FW.write(""+lnr.getLineNumber()+" "+line+"\r\n");
System.out.println(""+lnr.getLineNumber()+" "+line);
}
Collection.FW.write("\r\n");
System.out.println();
}
}

private static FileWriter FW;
private static FilenameFilter FNFilter=new FilenameFilter()
{
public boolean accept(File dir,String name)
{
return name.endsWith(".java");
}
};
private static FileFilter DFilter=new FileFilter()
{
public boolean accept(File pathname)
{
return pathname.isDirectory();
}
};
}

㈢ Java递归法读取文件目录

importjava.io.File;

publicclass${

publicstaticvoidmain(String[]args){

Stringpath="D:/";

test(path);
}

privatestaticvoidtest(Stringpath){
Filef=newFile(path);

File[]fs=f.listFiles();

if(fs==null){
return;
}

for(Filefile:fs){
if(file.isFile()){
System.out.println(file.getPath());
}else{
test(file.getPath());
}
}
}
}

㈣ Java实现读取某个路径下的文件目录

importjavax.swing.*;

importjavax.swing.table.AbstractTableModel;

importjavax.swing.table.TableCellRenderer;

importjavax.swing.event.TreeModelListener;

importjavax.swing.event.TreeSelectionListener;

importjavax.swing.event.TreeSelectionEvent;

importjavax.swing.tree.TreeModel;

importjavax.swing.tree.TreePath;

importjavax.swing.tree.TreeCellRenderer;

importjava.awt.*;

importjava.awt.event.*;

importjava.io.File;

importjava.io.FileInputStream;

importjava.io.IOException;

importjava.io.FileFilter;

importjava.util.Calendar;

importjava.util.ArrayList;

importjava.text.SimpleDateFormat;

importjava.text.MessageFormat;

/**

*@authorHardneedl

*/

{

=newDimension(300,200);

=newDimension(1024,768);

=newDimension(600,400);

privateJLabelstatusLabel;

privateJTreetree;

privateJTabledetailTable;

;

publicDimensiongetMaximumSize(){returnmaxSize;}

publicDimensiongetMinimumSize(){returnminSize;}

(){returnpreferredSize;}

publicStringgetTitle(){return"JavaExplorer";}

JavaExplorer()throwsHeadlessException{

init();

doLay();

attachListeners();

}

privatevoidinit(){

statusLabel=newJLabel(){publicColorgetForeground(){returnColor.BLUE;}};

tree=newJTree(newFileTreeModel());

tree.setCellRenderer(newDirCellRenderer());

detailTable=newJTable(tableModel=newFileTableModel());

detailTable.getColumnModel().getColumn(2).setCellRenderer(newTableCellRenderer(){

privateJLabellabel=newJLabel();

=newSimpleDateFormat("yyyy年mm月dd日HH时MM分ss秒");

(JTabletable,Objectvalue,booleanisSelected,booleanhasFocus,introw,intcolumn){

if(valueinstanceofCalendar){

Calendarcal=(Calendar)value;

label.setText(format.format(cal.getTime()));

}

returnlabel;

}

});

detailTable.getColumnModel().getColumn(0).setCellRenderer(newTableCellRenderer(){

privateJLabellabel=newJLabel();

(JTabletable,Objectvalue,booleanisSelected,booleanhasFocus,introw,intcolumn){

if(valueinstanceofFile){

Filef=(File)value;

label.setText(f.getName());

label.setForeground(f.isDirectory()?Color.RED:Color.BLACK);

}

returnlabel;

}

});

}

privatevoiddoLay(){

Containercontainer=getContentPane();

JSplitPanesplitPane=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,newJScrollPane(tree),newJScrollPane(detailTable));

container.add(splitPane,BorderLayout.CENTER);

container.add(statusLabel,BorderLayout.SOUTH);

pack();

}

privatevoidattachListeners(){

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

tree.addTreeSelectionListener(newSelectionListener());

tree.addTreeSelectionListener(new_DirSelectionListener());

DirCellSelectedListenerck=newDirCellSelectedListener(tree);

detailTable.addKeyListener(ck);

detailTable.addMouseListener(ck);

}

publicstaticvoidmain(String[]args){

newJavaExplorer().setVisible(true);

}

{

staticfinalStringroot="我的电脑";

privateFile[]rootFiles;

=newFileFilter(){

publicbooleanaccept(Filef){returnf.isDirectory();}

};

privateFileTreeModel(){rootFiles=File.listRoots();}

publicObjectgetRoot(){returnroot;}

publicObjectgetChild(Objectparent,intindex){

if(parent==getRoot())returnrootFiles[index];

if(parentinstanceofFile){

Filepf=(File)parent;

returnpf.listFiles(dirFilter)[index];

}

returnnull;

}

publicintgetChildCount(Objectparent){

if(parent==getRoot())returnrootFiles.length;

if(parentinstanceofFile){

Filepf=(File)parent;

File[]fs=pf.listFiles(dirFilter);

returnfs==null?0:fs.length;

}

return0;

}

publicbooleanisLeaf(Objectnode){returnfalse;}

publicvoidvalueForPathChanged(TreePathpath,ObjectnewValue){}

(TreeModelListenerl){}

(TreeModelListenerl){}

publicintgetIndexOfChild(Objectparent,Objectchild){

if(parent==getRoot()){

for(inti=0,j=rootFiles.length;i<j;i++)

if(rootFiles[i]==child)returni;

}

if(parentinstanceofFile){

Filepf=(File)parent;

File[]fs=pf.listFiles(dirFilter);

for(inti=0,j=fs.length;i<j;i++){

if(fs[i].equals(child))returni;

}

}

return-1;

}

}

{

publicintgetRowCount(){returndir==null||dir.isFile()?0:dir.listFiles().length;}

publicintgetColumnCount(){return3;}

privateFiledir;

privatevoidsetDir(Filedir){

this.dir=dir;

fireTableDataChanged();

}

publicClass<?>getColumnClass(intcolumnIndex){

switch(columnIndex){

case0:returnFile.class;

case1:returnInteger.class;

case2:returnCalendar.class;

default:returnString.class;

}

}

publicStringgetColumnName(intcolumn){

switch(column){

case0:return"名称";

case1:return"大小";

case2:return"修改日期";

default:return"";

}

}

publicObjectgetValueAt(introwIndex,intcolumnIndex){

File[]fs=dir.listFiles();

Filef=fs[rowIndex];

switch(columnIndex){

case0:returnf;

case1:

if(f.isDirectory())returnnull;

try{

if(f.canRead())

returnnewFileInputStream(f).available();

}catch(IOExceptione){

e.printStackTrace();

}

case2:

Calendarcl=Calendar.getInstance();

cl.setTimeInMillis(f.lastModified());

returncl;

}

returnnull;

}

}

privateclass_{

publicvoidvalueChanged(TreeSelectionEvente){

TreePathpath=e.getNewLeadSelectionPath();

if(path!=null){

Objectobj=path.getLastPathComponent();

if(objinstanceofFile){

Filef=(File)obj;

File[]fs=f.listFiles();

statusLabel.setText(fs==null?null:MessageFormat.format("{0}个文件",fs.length));

}

else

statusLabel.setText(null);

}

}

}

{

publicbooleanisOpaque(){returntrue;}

(JTreetree,Objectvalue,booleanselected,booleanexpanded,booleanleaf,introw,booleanhasFocus){

if(valueinstanceofFile){

Strings=((File)value).getName();

setText(s.isEmpty()?value.toString():s);

}

else

setText(value.toString());

setForeground(selected?Color.BLUE:Color.BLACK);

setBackground(selected?Color.YELLOW:Color.WHITE);

returnthis;

}

}

{

publicvoidvalueChanged(TreeSelectionEvente){

Objectobj=e.getNewLeadSelectionPath().getLastPathComponent();

if(objinstanceofFile){

tableModel.setDir((File)obj);

}

}

}

,MouseListener{

privateJTreetree;

(JTreet){tree=t;}

privatevoidaction(InputEvente){

if(einstanceofMouseEvent){

}

if(einstanceofKeyEvent){

}

}

privatevoidexpand(Filef){

if(f.isDirectory()){

ArrayList<File>L=newArrayList<File>();

L.add(f);

FileparentFile=f.getParentFile();

while(parentFile!=null){

L.add(parentFile);

parentFile=parentFile.getParentFile();

}

TreePathtreePath=newTreePath(FileTreeModel.root);

for(inti=L.size()-1;i>-1;i--){

treePath=treePath.pathByAddingChild(L.get(i));

}

tree.setSelectionPath(treePath);

}

}

publicvoidkeyTyped(KeyEvente){}

publicvoidkeyPressed(KeyEvente){

if(e.getKeyCode()!=KeyEvent.VK_ENTER)return;

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

introw=detailTable.getSelectedRow();

if(row!=-1){

Filef=(File)detailTable.getValueAt(row,0);

expand(f);

}

}

}

publicvoidkeyReleased(KeyEvente){

}

publicvoidmouseClicked(MouseEvente){

if(e.getClickCount()==2){

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

introw=detailTable.getSelectedRow();

if(row!=-1){

Filef=(File)detailTable.getValueAt(row,0);

expand(f);

}

}

}

}

publicvoidmousePressed(MouseEvente){

}

publicvoidmouseReleased(MouseEvente){

}

publicvoidmouseEntered(MouseEvente){

}

publicvoidmouseExited(MouseEvente){

}

}

}

㈤ java怎么循环读取目录下的文件内容

JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
1.不使用递归的方法调用。
public void traverseFolder1(String path) {
int fileNum = 0, folderNum = 0;
File file = new File(path);
if (file.exists()) {
LinkedList<File> list = new LinkedList<File>();
File[] files = file.listFiles();
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath());
list.add(file2);
fileNum++;
} else {
System.out.println("文件:" + file2.getAbsolutePath());
folderNum++;
}
}
File temp_file;
while (!list.isEmpty()) {
temp_file = list.removeFirst();
files = temp_file.listFiles();
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath());
list.add(file2);
fileNum++;
} else {
System.out.println("文件:" + file2.getAbsolutePath());
folderNum++;
}
}
}
} else {
System.out.println("文件不存在!");
}
System.out.println("文件夹共有:" + folderNum + ",文件共有:" + fileNum);

}
2.使用递归的方法调用
public static List<File> getFileList(String strPath) {
File dir = new File(strPath);
File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
if (files != null) {
for (int i = 0; i < files.length; i++) {
String fileName = files[i].getName();
if (files[i].isDirectory()) { // 判断是文件还是文件夹
getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
} else if (fileName.endsWith("avi")) { // 判断文件名是否以.avi结尾
String strFileName = files[i].getAbsolutePath();
System.out.println("---" + strFileName);
filelist.add(files[i]);
} else {
continue;
}
}

}
return filelist;
}

㈥ 如何查看java读取文件的路径

File类有两个常用方法可以得到文件路径一个是:Path(),另一个是:getAbsolutePath(),可以通过File类的实例调用这两个方法例如file.getAbsolutePath()其中file是File的实例对象。下面是一个具体例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

public class PathTest
{
public static void main(String[] args)
{
File file = new File(".\\src\\");
System.out.println(file.getAbsolutePath());
try
{
System.out.println(file.getCanonicalPath());
} catch (IOException e)
{
e.printStackTrace();
}
}
}

getAbsolutePath()和getCanonicalPath()的不同之处在于,getCanonicalPath()得到的是一个规范的路径,而getAbsolutePath()是用构造File对象的路径+当前工作目录。例如在上面的例子中.(点号)代表当前目录。getCanonicalPath()就会把它解析为当前目录但是getAbsolutePath()会把它解析成为目录名字(目录名字是点号)。
下面是上面程序在我电脑上的输出:
G:\xhuoj\konw\.\src\G:\xhuoj\konw\src\

㈦ Java 如何读取目录下的文件内容

Java读取目录下的文件内容,使用的是java的文件类,示例如下:

importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileReader;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.InputStreamReader;
importjava.io.RandomAccessFile;
importjava.io.Reader;

publicclassReadFromFile{
/**
*以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
*
*@paramfileName
*文件的名
*/
(StringfileName){
Filefile=newFile(fileName);
InputStreamin=null;
try{
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
//一次读一个字节
in=newFileInputStream(file);
inttempbyte;
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
}
in.close();
}catch(IOExceptione){
e.printStackTrace();
return;
}
try{
System.out.println("以字节为单位读取文件内容,一次读多个字节:");
//一次读多个字节
byte[]tempbytes=newbyte[100];
intbyteread=0;
in=newFileInputStream(fileName);
ReadFromFile.showAvailableBytes(in);
//读入多个字节到字节数组中,byteread为一次读入的字节数
while((byteread=in.read(tempbytes))!=-1){
System.out.write(tempbytes,0,byteread);
}
}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以字符为单位读取文件,常用于读文本,数字等类型的文件
*
*@paramfileName
*文件名
*/
(StringfileName){
Filefile=newFile(fileName);
Readerreader=null;
try{
System.out.println("以字符为单位读取文件内容,一次读一个字节:");
//一次读一个字符
reader=newInputStreamReader(newFileInputStream(file));
inttempchar;
while((tempchar=reader.read())!=-1){
//对于windows下, 这两个字符在一起时,表示一个换行。
//但如果这两个字符分开显示时,会换两次行。
//因此,屏蔽掉 ,或者屏蔽 。否则,将会多出很多空行。
if(((char)tempchar)!=' '){
System.out.print((char)tempchar);
}
}
reader.close();
}catch(Exceptione){
e.printStackTrace();
}
try{
System.out.println("以字符为单位读取文件内容,一次读多个字节:");
//一次读多个字符
char[]tempchars=newchar[30];
intcharread=0;
reader=newInputStreamReader(newFileInputStream(fileName));
//读入多个字符到字符数组中,charread为一次读取字符数
while((charread=reader.read(tempchars))!=-1){
//同样屏蔽掉 不显示
if((charread==tempchars.length)
&&(tempchars[tempchars.length-1]!=' ')){
System.out.print(tempchars);
}else{
for(inti=0;i<charread;i++){
if(tempchars[i]==' '){
continue;
}else{
System.out.print(tempchars[i]);
}
}
}
}

}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以行为单位读取文件,常用于读面向行的格式化文件
*
*@paramfileName
*文件名
*/
(StringfileName){
Filefile=newFile(fileName);
BufferedReaderreader=null;
try{
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader=newBufferedReader(newFileReader(file));
StringtempString=null;
intline=1;
//一次读入一行,直到读入null为文件结束
while((tempString=reader.readLine())!=null){
//显示行号
System.out.println("line"+line+":"+tempString);
line++;
}
reader.close();
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*随机读取文件内容
*
*@paramfileName
*文件名
*/
(StringfileName){
RandomAccessFilerandomFile=null;
try{
System.out.println("随机读取一段文件内容:");
//打开一个随机访问文件流,按只读方式
randomFile=newRandomAccessFile(fileName,"r");
//文件长度,字节数
longfileLength=randomFile.length();
//读文件的起始位置
intbeginIndex=(fileLength>4)?4:0;
//将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[]bytes=newbyte[10];
intbyteread=0;
//一次读10个字节,如果文件内容不足10个字节,则读剩下的字节。
//将一次读取的字节数赋给byteread
while((byteread=randomFile.read(bytes))!=-1){
System.out.write(bytes,0,byteread);
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(randomFile!=null){
try{
randomFile.close();
}catch(IOExceptione1){
}
}
}
}

/**
*显示输入流中还剩的字节数
*
*@paramin
*/
(InputStreamin){
try{
System.out.println("当前字节输入流中的字节数为:"+in.available());
}catch(IOExceptione){
e.printStackTrace();
}
}

publicstaticvoidmain(String[]args){
StringfileName="C:/temp/newTemp.txt";
ReadFromFile.readFileByBytes(fileName);
ReadFromFile.readFileByChars(fileName);
ReadFromFile.readFileByLines(fileName);
ReadFromFile.readFileByRandomAccess(fileName);
}
}

㈧ java读取文件路径

你的头是e://tttt11.PNG不是e://tttt11//1.PNG???
如果头是e://tttt11//1.PNG,filepath没有用,去掉。
这段这么改:
for (i=0; i <= str.length(); i += 2) {
if (i == str.length() - 1 || i == str.length() - 2)
break;
else
fileName = str.substring(i);
}

// System.out.println(filePath);
if(ii!=100)
fileName = str.substring(i);
...........后面不改回.

如果头是e://tttt11.PNG,那这个和下面的循环规答律不一样,大概写下:
if(ii==1)filePath=".PNG";
把我上面修改后的代码加到else里就行了(用我上面修改后的代码,不然你的尾还是显不出来).

㈨ java读取指定目录下的文件内容

publicclassReadFromFile{
/**
*以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
*/
(StringfileName){
Filefile=newFile(fileName);
InputStreamin=null;
try{
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
//一次读一个字节
in=newFileInputStream(file);
inttempbyte;
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
}
in.close();
}catch(IOExceptione){
e.printStackTrace();
return;
}
try{
System.out.println("以字节为单位读取文件内容,一次读多个字节:");
//一次读多个字节
byte[]tempbytes=newbyte[100];
intbyteread=0;
in=newFileInputStream(fileName);
ReadFromFile.showAvailableBytes(in);
//读入多个字节到字节数组中,byteread为一次读入的字节数
while((byteread=in.read(tempbytes))!=-1){
System.out.write(tempbytes,0,byteread);
}
}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(in!=null){
try{
in.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以字符为单位读取文件,常用于读文本,数字等类型的文件
*/
(StringfileName){
Filefile=newFile(fileName);
Readerreader=null;
try{
System.out.println("以字符为单位读取文件内容,一次读一个字节:");
//一次读一个字符
reader=newInputStreamReader(newFileInputStream(file));
inttempchar;
while((tempchar=reader.read())!=-1){
//对于windows下, 这两个字符在一起时,表示一个换行。
//但如果这两个字符分开显示时,会换两次行。
//因此,屏蔽掉 ,或者屏蔽 。否则,将会多出很多空行。
if(((char)tempchar)!=' '){
System.out.print((char)tempchar);
}
}
reader.close();
}catch(Exceptione){
e.printStackTrace();
}
try{
System.out.println("以字符为单位读取文件内容,一次读多个字节:");
//一次读多个字符
char[]tempchars=newchar[30];
intcharread=0;
reader=newInputStreamReader(newFileInputStream(fileName));
//读入多个字符到字符数组中,charread为一次读取字符数
while((charread=reader.read(tempchars))!=-1){
//同样屏蔽掉 不显示
if((charread==tempchars.length)
&&(tempchars[tempchars.length-1]!=' ')){
System.out.print(tempchars);
}else{
for(inti=0;i<charread;i++){
if(tempchars[i]==' '){
continue;
}else{
System.out.print(tempchars[i]);
}
}
}
}

}catch(Exceptione1){
e1.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*以行为单位读取文件,常用于读面向行的格式化文件
*/
(StringfileName){
Filefile=newFile(fileName);
BufferedReaderreader=null;
try{
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader=newBufferedReader(newFileReader(file));
StringtempString=null;
intline=1;
//一次读入一行,直到读入null为文件结束
while((tempString=reader.readLine())!=null){
//显示行号
System.out.println("line"+line+":"+tempString);
line++;
}
reader.close();
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(reader!=null){
try{
reader.close();
}catch(IOExceptione1){
}
}
}
}

/**
*随机读取文件内容
*/
(StringfileName){
RandomAccessFilerandomFile=null;
try{
System.out.println("随机读取一段文件内容:");
//打开一个随机访问文件流,按只读方式
randomFile=newRandomAccessFile(fileName,"r");
//文件长度,字节数
longfileLength=randomFile.length();
//读文件的起始位置
intbeginIndex=(fileLength>4)?4:0;
//将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
byte[]bytes=newbyte[10];
intbyteread=0;
//一次读10个字节,如果文件内容不足10个字节,则读剩下的字节。
//将一次读取的字节数赋给byteread
while((byteread=randomFile.read(bytes))!=-1){
System.out.write(bytes,0,byteread);
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
if(randomFile!=null){
try{
randomFile.close();
}catch(IOExceptione1){
}
}
}
}

/**
*显示输入流中还剩的字节数
*/
(InputStreamin){
try{
System.out.println("当前字节输入流中的字节数为:"+in.available());
}catch(IOExceptione){
e.printStackTrace();
}
}

publicstaticvoidmain(String[]args){
StringfileName="C:/temp/newTemp.txt";
ReadFromFile.readFileByBytes(fileName);
ReadFromFile.readFileByChars(fileName);
ReadFromFile.readFileByLines(fileName);
ReadFromFile.readFileByRandomAccess(fileName);
}
}

㈩ java读取本地文件路径怎么写

构造File对象,使用File对象取上级目录,再取绝专对路属径 File f = new File("c:\\temp\\01\\1.txt"); if(f.exists()){ System.out.println(f.getParentFile().getAbsolutePath()); }

热点内容
涂鸦论文 发布:2021-03-31 13:04:48 浏览:698
手机数据库应用 发布:2021-03-31 13:04:28 浏览:353
版面217 发布:2021-03-31 13:04:18 浏览:587
知网不查的资源 发布:2021-03-31 13:03:43 浏览:713
基金赎回参考 发布:2021-03-31 13:02:08 浏览:489
悬疑故事范文 发布:2021-03-31 13:02:07 浏览:87
做简单的自我介绍范文 发布:2021-03-31 13:01:48 浏览:537
战略地图参考 发布:2021-03-31 13:01:09 浏览:463
收支模板 发布:2021-03-31 13:00:43 浏览:17
电气学术会议 发布:2021-03-31 13:00:32 浏览:731