导航:首页 > 文件教程 > idea加载图片所在文件夹

idea加载图片所在文件夹

发布时间:2023-11-15 11:23:16

㈠ idea中获取项目中文件相对路径的方法

想要读取该项目中的resources下的prop文件夹中的text.txt文件。

// 读文件String path

this.getClass().getClassLoader().getResource("./prop/text.txt").getPath();

FileReader fr = new FileReader(path);

BufferedReader br = new BufferedReader(fr);

String str = null;while((str = br.readLine()) != null) {

System.out.println(str);

}// 关闭流br.close();

fr.close();

读文件:

public void load(String path) {

er br = null;

try {

br = new BufferedReader(new FileReader(path));

String line = "";

while ((line = br.readLine()) != null) {

m_tbl.put(Integer.parseInt(line), true);

}

br.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

(1)idea加载图片所在文件夹扩展阅读:

解决相对路径找不到的问题:

1、采用绝对路径;

2、还是使用相对路径,这时用类加载器加载文件路径。代码如下:

public void load(String path) {

BufferedReader br = null;

try {

InputStream in = SetTable.class.getClassLoader().getResourceAsStream(path);

br = new BufferedReader(new InputStreamReader(in, "UTF-8"));

String line = "";

while ((line = br.readLine()) != null) {

m_tbl.put(Integer.parseInt(line), true);

}

br.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}



㈡ intellij idea 怎么在project里的src创建图片文件夹

之前一直喜欢在eclipse写代码,最近迁移到了idea 编辑器,发现有很多不习惯的地方,比如eclipse能够回新建一个答Source Folder(资源管理器)这么一个东西,而在idea无法新建这样的一种包,idea只能新建一个普通的directory,然后在directory里面不能新建Java class 等等,之前一直是使用eclipse和idea同时开一个项目,然后在eclipse 中新建完之后,再在idea中使用。。。。。。方式很low,还请大家见谅。

阅读全文

与idea加载图片所在文件夹相关的资料

热点内容
微信文件怎么填 浏览:87
燕十八老师精通mysql视频教程 浏览:255
汽车保养数据怎么清 浏览:629
pdf文件图像打不开 浏览:176
msp430时钟程序 浏览:660
查看sd卡文件系统格式 浏览:696
c盘中显示隐藏文件 浏览:951
苹果升级系统白屏 浏览:136
三菱gxplc编程软件如何使用 浏览:710
海康威视手机app怎么看不了 浏览:482
wordpress下载中心插件 浏览:402
微信限制字数是多少 浏览:20
策划输出主要从哪些文件来 浏览:174
网络营销找什么工作 浏览:372
tcl匹配文件名的正则表达式 浏览:461
音频文件数据量为何8 浏览:534
有哪些分享学习的网站 浏览:174
小程序文件发到微信电脑如何打开 浏览:265
四星五星做号工具 浏览:920
qq邮箱怎么发送视频文件 浏览:453

友情链接