标签: filenotfoundexception

File.Move,为什么我得到FileNotFoundException?该文件存在

由于程序正在迭代文件,因此非常奇怪!outfolder和infolder都在H:/我的外部HD使用Windows 7.想法是移动所有只包含扩展db和svn-base文件的文件夹.当我尝试移动文件夹时,我得到一个例外.VS2010告诉我它无法找到dir中指定的文件夹.这段代码是通过dir迭代的,所以它怎么能找不到它!这很奇怪.

        string []theExt = new string[] { "db", "svn-base" };
        foreach (var dir in Directory.GetDirectories(infolder))
        {
            bool hit = false;
            if (Directory.GetDirectories(dir).Count() > 0)
                continue;
            foreach (var f in Directory.GetFiles(dir))
            {
                var ext = Path.GetExtension(f).Substring(1);
                if(theExt.Contains(ext) == false)
                {
                    hit = true;
                    break;
                }
            }
            if (!hit)
            {
                var dst = outfolder + "\\" + Path.GetFileName(dir);
                File.Move(dir, outfolder); //FileNotFoundException: Could not find file dir.
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

.net filenotfoundexception

0
推荐指数
1
解决办法
594
查看次数

在Android中从URL保存图像时出现只读错误

我正在尝试从Android应用程序中的Web URL保存图像,但是当我运行它时,日志cat会抛出一个异常,说它是"只读".我不知道最近发生了什么.

这是我的下载类:

  public class ImageDownload {

public static void downloader(String imageURL, String fileName) { 
        try {
                URL url = new URL("http://www.exampleurl.com/" + imageURL); 
                File file = new File(fileName);


                URLConnection con = url.openConnection();

                InputStream is = con.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);

                ByteArrayBuffer baf = new ByteArrayBuffer(50);
                int current = 0;
                while ((current = bis.read()) != -1) {
                        baf.append((byte) current);
                }

                FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.close();

        } catch (IOException e) {
                Log.d("Downloader", "Error: " + e);
        }

} …
Run Code Online (Sandbox Code Playgroud)

android urlconnection filenotfoundexception fileoutputstream

0
推荐指数
1
解决办法
8319
查看次数

调用抛出FileNotFoundException的方法

我很确定这很容易,但我找不到直截了当的答案.如何调用方法throws FileNotFoundException

这是我的方法:

private static void fallingBlocks() throws FileNotFoundException
Run Code Online (Sandbox Code Playgroud)

java methods filenotfoundexception throws

0
推荐指数
1
解决办法
3万
查看次数

FileNotFoundException仅在Android应用程序中

我怎么只在android应用程序中获取FileNotFoundException,当我从普通的Java应用程序中读取它时,它找到了该目录.

我正在使用相同的代码.

{
        BufferedReader bufRdr;
         contacts = new ArrayList<Contacts>();


        File randomContactsFile = new File(("C://test//randomcontacts.txt"));
        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();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Run Code Online (Sandbox Code Playgroud)

这是例外:

 10-05 08:04:37.151: WARN/System.err(334):
 java.io.FileNotFoundException: /C:/test/randomcontacts.txt (No …
Run Code Online (Sandbox Code Playgroud)

java android file filenotfoundexception

0
推荐指数
1
解决办法
1113
查看次数

FileNotFoundException - 进程无法访问该文件

我在学校有一个网络驱动器,我有能力正常读取和写入,但是当我使用java来获取现有的文本文件并尝试写入它时,我得到了以下异常:

java.io.FileNotFoundException: p:\CompSci_CheckIn_Name.txt (The process cannot access the file because it is being used by another process)
Run Code Online (Sandbox Code Playgroud)

我可以读得很好,但是当我尝试写它时,它会抛出一个例外.我可以写入桌面并从桌面读取所有内容,但是当我尝试使用网络驱动器时,它会放弃.我怎么能解决这个问题?

file = new File(directories[i], "CompSci_CheckIn_Name.txt");
readName = new BufferedReader(new FileReader(file));
userName = readName.readLine();
passed = true;
Run Code Online (Sandbox Code Playgroud)

写作

write = new PrintWriter(file);
write.println(newUser);
write.flush();
userName = newUser;
write.close();
Run Code Online (Sandbox Code Playgroud)

我已经尝试过BufferedWriter没有运气,同样的结果.

java file-io filenotfoundexception

0
推荐指数
1
解决办法
8629
查看次数

无法找到.txt文件的原因?

当我运行这个程序时,它找不到我指向它的文件.我把两个文本文件放到程序的src文件夹中,据我所知,我要做的就是调用它File f = new File("filename.txt").但这不起作用.我也尝试使用内部的确切目录,File()但它也不起作用.这些文件只包含一个名称和金额.有任何想法吗?

import java.io.*;
import java.util.Scanner;

class Donors {
File donor2;
File donor3;
Scanner inD2;
Scanner inD3;

Donors(File d2, File d3){
    donor2 = d2;
    donor3 = d3;
}

double totalDonations(){
    double total = 0;
    try{
    inD2 = new Scanner(donor2);
    while(inD2.hasNext()){
        total += inD2.nextDouble();
    }
    }catch(java.io.FileNotFoundException e){
        System.out.println("File can't be found");
    }

    try{
    inD3 = new Scanner(donor3);
    while(inD3.hasNext()){
        total += inD3.nextDouble();
    }
    }catch(java.io.FileNotFoundException e){
        System.out.println("File can't be found");
    }

    return total;
}

public void …
Run Code Online (Sandbox Code Playgroud)

java text file filenotfoundexception

0
推荐指数
1
解决办法
92
查看次数

为什么我看不到我在工作目录中创建的文本文件?

File f = new File("textfile.txt");
        System.out.println(f.getAbsolutePath());
Run Code Online (Sandbox Code Playgroud)

这会打印出文本文件的路径,但是当我转到它的目录时,文本文件就不存在了.文本文件是隐藏还是未创建?

java file filenotfoundexception

0
推荐指数
1
解决办法
32
查看次数

如何将uri从onActivityresult转换为真实文件路径以导入该文件

我正在从URI String path = uri.getPath()作为/document/primary:Download/West Delhi Mis June.xlsx

但是当我写File file = new File(path)它时会抛出FileNotFoundException.请帮忙.

这是我的代码:

public void getdata(File fil){

    try{
        Workbook w;
        w = Workbook.getWorkbook(fil);
        Sheet sheet = w.getSheet(0);
        for (int j = 1; j<sheet.getRows(); j++){

            Cell c1 = sheet.getCell(0,j);
            Cell c2 = sheet.getCell(1,j);
            Cell c3 = sheet.getCell(2,j);
            Cell c4 = sheet.getCell(3,j);
            Cell c5 = sheet.getCell(4,j);
            Cell c6 = sheet.getCell(5,j);
            Cell c7 = sheet.getCell(6,j);
            Cell c8 = sheet.getCell(7,j);
            Cell c9 = sheet.getCell(8,j);
            Cell c10 = …
Run Code Online (Sandbox Code Playgroud)

java android filenotfoundexception

0
推荐指数
1
解决办法
235
查看次数

Android - FileNotFoundException 打开失败:EACCES(权限被拒绝)

我有一个应用程序,在登录时我从我的服务器下载图像。在第一次登录时,一切正常,但是当我卸载应用程序并再次安装时,出现此异常:

java.io.FileNotFoundException:/storage/emulated/0/Android/data/com.gilapp.android.app/files/images/book_118.png:打开失败:EACCES(权限被拒绝)

并且无法保存图像。

当我尝试创建输出流时会发生这种情况:

OutputStream output = new FileOutputStream(filePath);
Run Code Online (Sandbox Code Playgroud)

转到应用信息-> 存储-> 清除数据后进行第二次安装时,图像下载正常

另一个重要的一点是它只发生在三星的平板电脑上: SM-T800 (API level 23)

在其他设备中它没有发生,我测试的设备:Samsung SM-G900H (API level 23), Asus P028 (API level 24), Samsung SM-G950F (API level 28)

android filenotfoundexception samsung-galaxy

0
推荐指数
1
解决办法
5345
查看次数

尝试保存位图图像时始终出现“权限被拒绝”或“没有此类文件或目录”的情况。我应该怎么办?

我正在尝试通过以下代码保存位图图像:

File sdcard = Environment.getExternalStorageDirectory();
            String filename = "test";
            File folder = new File(sdcard, "/Download");
            Log.v("ImageStorage1", "EXiST?: " + folder.exists());
            folder.mkdirs();
            Log.v("ImageStorage2", "EXIST!: " + folder.exists());
            Log.v("ImageStorage", "Folder: " + folder);
            File file = new File(folder, filename + ".jpg");

            try {
                FileOutputStream out = new FileOutputStream(file.getAbsoluteFile());
                result.compress(Bitmap.CompressFormat.JPEG, 90, out);
                out.flush();
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
Run Code Online (Sandbox Code Playgroud)

我还在清单文件中使用:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)

但我得到了这个:

V/ImageStorage1: EXiST?: true
V/ImageStorage2: EXIST!: true
W/System.err: java.io.FileNotFoundException: 
/storage/emulated/0/Download/test.jpg (Permission denied)
    W/System.err:     at java.io.FileOutputStream.open0(Native Method)
    W/System.err:     at java.io.FileOutputStream.open(FileOutputStream.java:287) …
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception permission-denied

-1
推荐指数
1
解决办法
1417
查看次数

FileNotFoundException(找不到DLL)

我在客户的一台机器上遇到了这个奇怪的错误.它抛出FileNotFoundException,但是那个DLL肯定就在那个带有Executable的文件夹中..为什么它找不到它?请指教..

.net c# dll filenotfoundexception

-2
推荐指数
1
解决办法
3101
查看次数

FileNotFoundException的方法

以下不断报告相同的错误.

public static ArrayList<File> findMatches(File directory, String pattern) throws FileNotFoundException {
60         ArrayList<File> container = new ArrayList<File>();
61 
62         return container;
63     }
Run Code Online (Sandbox Code Playgroud)

我用以下方式初始化它

ArrayList<File> matched = findMatches(new File("hw9"), "FileFinder.java");
Run Code Online (Sandbox Code Playgroud)

错误:错误:未报告的异常FileNotFoundException; 必须被抓住或宣布被抛出

有解决方案吗

编辑

终于找到了怎么做!

public static ArrayList<File> findMatches(File directory, String pattern) throws FileNotFoundException {
    ArrayList<File> container = new ArrayList<File>();

    try {
        if (!directory.exists() && !directory.canRead() && !directory.isDirectory()) {
            throw new FileNotFoundException();
        }
        File[] fileStack = directory.listFiles();
        for (int i = 0; i < fileStack.length; i++) {
            if (patternMatches(pattern, fileStack[i].getName())) …
Run Code Online (Sandbox Code Playgroud)

java filenotfoundexception

-2
推荐指数
1
解决办法
175
查看次数

如何捕获"FileNotFoundException"异常?

我是编程新手,我想弄清楚如何捕获错误"FileNotFoundException".我的代码是为了搜索现有的文本文档(从输入到文本框中的内容)并将其加载到我的listbox1.我解决了这个问题.但是,出现了一个新问题!如果用户输入了错误的名称/数字,它只会使应用程序崩溃,导致无法找到该文件.有没有办法让程序显示错误消息"找不到文件".或者根本不崩溃整个程序?提前致谢!

     private void btnEnter_Click(object sender, EventArgs e)
    {   
        FileInfo file = new FileInfo(txtExisting.Text + ".txt");
        StreamReader stRead = file.OpenText();
        while (!stRead.EndOfStream)
        {
            listBox1.Items.Add(stRead.ReadLine()); 
        }  
    }
Run Code Online (Sandbox Code Playgroud)

c# filenotfoundexception

-2
推荐指数
1
解决办法
4338
查看次数