找不到文件
private void readRandomContacts() throws IOException
{
BufferedReader bufRdr;
contacts = new ArrayList<Contacts>();
File randomContactsFile = new File("C:\randomContacts.csv");
try {
bufRdr = new BufferedReader(new FileReader(randomContactsFile));
String line = null;
String[] a = new String[2];
while ((line = bufRdr.readLine()) != null)
{
a = line.split(",");
Contacts c = new Contacts(a[0], a[1], a[1], a[1], a[2]);
contacts.add(c);
}
} catch (FileNotFoundException e) {
Log.d("file not found", "check");
e.printStackTrace();
}
我似乎无法让它找到该文件,并且 randomContacts.csv 确实存在于 C 目录中。有什么帮助吗?
private void readRandomContacts() throws IOException
{
BufferedReader bufRdr;
contacts = new ArrayList<Contacts>();
File randomContactsFile = new File("C:\randomContacts.csv");
try {
bufRdr = new BufferedReader(new FileReader(randomContactsFile));
String line = null;
String[] a = new String[2];
while ((line = bufRdr.readLine()) != null)
{
a = line.split(",");
Contacts c = new Contacts(a[0], a[1], a[1], a[1], a[2]);
contacts.add(c);
}
} catch (FileNotFoundException e) {
Log.d("file not found", "check");
e.printStackTrace();
}
I cannot seem to make it find the file and randomContacts.csv does indeed exist in the C directory. Any help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用:
有关字符和转义序列的一些信息,请参阅此处 。
Try with:
See here for some information about characters and escape sequences.
应该是
你需要转义
\
,否则java会将\r
读为回车符。should be
You need to escape
\
,otherwise, java would read\r
as carriage return.你也可以这样做(前斜杠):
you can also do this (frontslash):