GVKun编程网logo

java.io.FileNotFoundException:in.txt,(系统找不到指定的文件)(java.io.ioexception系统找不到指定的路径)

28

本文将分享java.io.FileNotFoundException:in.txt,的详细内容,并且还将对系统找不到指定的文件进行详尽解释,此外,我们还将为大家带来关于android–java.io.

本文将分享java.io.FileNotFoundException:in.txt,的详细内容,并且还将对系统找不到指定的文件进行详尽解释,此外,我们还将为大家带来关于android – java.io.FileNotFoundException:/file/path.jpg open failed:ENOENT(没有这样的文件或目录)、FileNotFoundError: [Errno 2] 没有那个文件或目录 | FileNotFoundError: [WinError 2] 系统找不到指定的文件:、FileNotFoundError: [WinError 2] 系统找不到指定的文件、FileNotFoundError: [WinError 2] 系统找不到指定的文件。 解决方案的相关知识,希望对你有所帮助。

本文目录一览:

java.io.FileNotFoundException:in.txt,(系统找不到指定的文件)(java.io.ioexception系统找不到指定的路径)

java.io.FileNotFoundException:in.txt,(系统找不到指定的文件)(java.io.ioexception系统找不到指定的路径)

我收到以下错误

java.io.FileNotFoundException: in.txt, (The system cannot find the file specified)    at java.io.FileInputStream.open(Native Method)    at java.io.FileInputStream.<init>(Unknown Source)    at java.io.FileInputStream.<init>(Unknown Source)    at java.io.FileReader.<init>(Unknown Source)    at FileTest.main(FileTest.java:50)

但我可以肯定地说,我已经在src,bin和根目录下创建了一个in.txt文件。我还尝试在主要参数中指定完整目录,但仍然无法正常工作。为什么Eclipse不选择它?

import java.io.*;public class FileTest {    public static void main(String[] args) {        try {            String inFileName = args[0];            String outFileName = args[1];            BufferedReader ins = new BufferedReader(new FileReader(inFileName));            BufferedReader con = new BufferedReader(new InputStreamReader(System.in));            PrintWriter outs = new PrintWriter(new FileWriter(outFileName));            String first = ins.readLine(); // read from file            while (first != null) {                System.out.print("Type in a word to follow " + first + ":");                String second = con.readLine(); // read from console                // append and write                outs.println(first + ", " + second);                first = ins.readLine(); // read from file            }            ins.close();            outs.close();        } catch (IOException ex) {            ex.printStackTrace(System.err);            System.exit(1);        }    }}

答案1

小编典典

我获取了您的代码,并使用以下命令行参数执行了该代码:

in.txt out.txt

它完全没有问题。检查您的命令行。

android – java.io.FileNotFoundException:/file/path.jpg open failed:ENOENT(没有这样的文件或目录)

android – java.io.FileNotFoundException:/file/path.jpg open failed:ENOENT(没有这样的文件或目录)

我试图将图像保存到 parse.com.我需要将其转换为字节数组.我决定尝试这样做的方法是使用 apache commons-io.它工作不正常.这是我的代码片段;

private void saveImage() throws IOException {
    // Todo Auto-generated method stub

    InputStream header = new FileInputStream("/ClashMMA/res/drawable-hdpi/beatdown.jpg");

    ParseFile file = new ParseFile(toByteArray(header));
    try{
        file.save();
    } catch (ParseException e) {
        e.printstacktrace();
    }

    ParSEObject displayImage = new ParSEObject("displayImage");
    displayImage.put("header",file);
    try{
        displayImage.save();
    } catch (ParseException e1){
        e1.printstacktrace();
    }
}


private byte[] toByteArray(InputStream header) throws IOException {
    // Todo Auto-generated method stub
     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        int l;
        byte[] data = new byte[1024];
        while ((l = header.read(data,data.length)) != -1) {
          buffer.write(data,l);
        }
        buffer.flush();
        return buffer.toByteArray();

}

而我的错误是这样的;

java.io.FileNotFoundException:/ClashMMA/res/drawable-hdpi/beatdown.jpg:open Failed:ENOENT(没有这样的文件或目录)

但我确信文件在那里,因为我去了我的文件目录(在eclipse中),右键单击,然后单击copy Qualified Name.这基本上复制了文件路径.我已经尝试了一些其他路径,例如关闭我的计算机,以及我的src文件夹.有人可以告诉我我做错了什么吗?为什么它不会读取文件,实际上它在那里?详细解释请.

解决方法

Eclipse项目中的文件不在(真实的或模拟的)Android文件系统中,这就是Android FileInputStream所在的位置. (有充分的理由!Eclipse的主机文件系统不会出现在真正的Android设备上.)

你基本上有两个选择:

>将它们放入APK存档中,以便您可以使用getSystemResourceAsstream加载它们:请参阅How to load image for Android ImageView from classpath?>将文件复制到Android文件系统中,以便FileInputStream可以找到它们.

FileNotFoundError: [Errno 2] 没有那个文件或目录 | FileNotFoundError: [WinError 2] 系统找不到指定的文件:

FileNotFoundError: [Errno 2] 没有那个文件或目录 | FileNotFoundError: [WinError 2] 系统找不到指定的文件:

如何解决FileNotFoundError: [Errno 2] 没有那个文件或目录 | FileNotFoundError: [WinError 2] 系统找不到指定的文件:?

我正在尝试使用 Django 模板上传文件,但在 save_project 上我收到此回溯错误

FileNotFoundError: [WinError 2] The system cannot find the file specified: ''E:\\forefront-v1.0\\media\\uploads\\temp\\10\\Video%20Sensor%20-%2013370_1798858.mp4'' -> ''E:\\forefront-v1.0\\media/uploads/project-videos/Video%20Sensor%20-%2013370_1798858.mp4''

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\exception.py",line 34,in inner
    response = get_response(request)
  File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\base.py",line 115,in _get_response
    response = self.process_exception_by_middleware(e,request)
  File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\base.py",line 113,in _get_response
    response = wrapped_callback(request,*callback_args,**callback_kwargs)
  File "E:\forefront-v1.0\venv\lib\site-packages\django\views\generic\base.py",line 71,in view
    return self.dispatch(request,*args,**kwargs)
  File "E:\forefront-v1.0\venv\lib\site-packages\django\contrib\auth\mixins.py",line 52,in dispatch
    return super().dispatch(request,line 109,**kwargs)
  File "E:\forefront-v1.0\venv\lib\site-packages\django\views\generic\base.py",line 97,in dispatch
    return handler(request,**kwargs)
  File "E:\forefront-v1.0\projects\views.py",line 2660,in post
    project_id = self.save_project(
  File "E:\forefront-v1.0\projects\views.py",line 2792,in save_project
    video1 = self.upload_video_locally(video1) if video1 else None
  File "E:\forefront-v1.0\projects\views.py",line 2872,in upload_video_locally
    shutil.move(temp_file_path,saved_file_path)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\python39\lib\shutil.py",line 826,in move
    copy_function(src,real_dst)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\python39\lib\shutil.py",line 435,in copy2
    copyfile(src,dst,follow_symlinks=follow_symlinks)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\python39\lib\shutil.py",line 264,in copyfile
    with open(src,''rb'') as fsrc,open(dst,''wb'') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: ''E:\\forefront-v1.0\\media\\uploads\\temp\\10\\Video%20Sensor%20-%2013370_1798858.mp4''
[26/Jul/2021 13:12:27] "POST /upload/ HTTP/1.1" 500 23208

在项目 settings.py

# Upload

MEDIA_URL = ''/media/''
MEDIA_ROOT = os.path.join(BASE_DIR,''media'')

enter image description here

这是有问题的函数。在views.py

def save_project(
        self,image,name,excerpt,body,caption1,caption2,description1,description2,image1,image2,video,video1,video2,authors_arr,paperlink,):
        video = self.upload_video_locally(video) if video else None
        video1 = self.upload_video_locally(video1) if video1 else None
        video2 = self.upload_video_locally(video2) if video2 else None
        if self.request.POST.get("previewed") or video is not None:
            image = self.upload_file_locally(image,"banner",1) if image else None
        else:
            image = self.upload_file_locally(image,0) if image else None
        if video1 is not None:
            image1 = self.upload_file_locally(image1,"upm-img1",1) if image1 else None
        else:
            image1 = self.upload_file_locally(image1,0) if image1 else None
        if video2 is not None:
            image2 = self.upload_file_locally(image2,"upm-img2",1) if image2 else None
        else:
            image2 = self.upload_file_locally(image2,0) if image2 else None
        # video2 = self.upload_video_locally(video2) if video1 else None
        # image2 = self.upload_file_locally(image2,''upm-img2'',0) if image2 else None
        # image3 = self.upload_file_locally(image3,''upm-img3'',0) if image3 else None
        self.upload_file_to_s3()  # upload all files to amazon s3
        # self.upload_file_locally(image,True)
        save_project = Project(
            image=image,name=name,excerpt=excerpt,body=body,caption1=caption1,caption2=caption2,description1=description1,description2=description2,image1=image1,image2=image2,video=video,video1=video1,video2=video2,paperLink=paperlink,)
        save_project.save()
        # getting authors from request session
        login_user_status = 0
        for author in authors_arr:
            if self.request.user.customuser.member.id == int(author["id"]):
                login_user_status = 1

            get_author = Member.objects.get(id=int(author["id"]))
            save_project.authors.add(get_author)

        if login_user_status == 0:
            get_author = Member.objects.get(id=self.request.user.customuser.member.id)
            save_project.authors.add(get_author)

        return save_project.id

所以请帮我找到可能是问题的解决方案,我们可以解决这个问题。 我相信

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

FileNotFoundError: [WinError 2] 系统找不到指定的文件

FileNotFoundError: [WinError 2] 系统找不到指定的文件

用Idle运行Python脚本的时候发现如下错误:

Traceback (most recent call last):
  File "D:\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "D:\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "D:\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

后来在stackoverflow上找到如下解决办法:

In Windows , to use echo in subprocess, you would need to use shell=True . This is because echo is not a separate executable, but rather a built-in command for the windows command line. Example -
在windows 在子进程中使用echo,需要设置 shell =True,因为 echo 不是单独的命令,而是window CMD 内置的命令

process1 = subprocess.Popen(command1,stdout=subprocess.PIPE,shell=True)

Also, please do note, you should only use shell=True when absolutely necessary (as in this case , to use echo in windows in subprocess).

并且,需要注意,只有在绝对需要的情况下才使用shell=True

找到 subprocess.py脚本,将对应行加上shell=true 参数。

FileNotFoundError: [WinError 2] 系统找不到指定的文件。 解决方案

FileNotFoundError: [WinError 2] 系统找不到指定的文件。 解决方案

用 Idle 运行 Python 脚本的时候发现如下错误:

Traceback (most recent call last): File "C:\Users\DangKai\Desktop\pythonUI-unittest-selenium\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start stdin=PIPE) File "D:\Software\Python37\lib\subprocess.py", line 756, in init restore_signals, start_new_session) File "D:\Software\Python37\lib\subprocess.py", line 1155, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。

后来在 stackoverflow 上找到如下解决办法:

In Windows , to use echo in subprocess, you would need to use shell=True . This is because echo is not a separate executable, but rather a built-in command for the windows command line. Example - 在 windows 在子进程中使用 echo,需要设置 shell =True,因为 echo 不是单独的命令,而是 window CMD 内置的命令

process1 = subprocess.Popen(command1,stdout=subprocess.PIPE,shell=True) Also, please do note, you should only use shell=True when absolutely necessary (as in this case , to use echo in windows in subprocess).

并且,需要注意,只有在绝对需要的情况下才使用 shell=True

找到 subprocess.py 脚本,将对应行加上 shell=true 参数

今天关于java.io.FileNotFoundException:in.txt,系统找不到指定的文件的讲解已经结束,谢谢您的阅读,如果想了解更多关于android – java.io.FileNotFoundException:/file/path.jpg open failed:ENOENT(没有这样的文件或目录)、FileNotFoundError: [Errno 2] 没有那个文件或目录 | FileNotFoundError: [WinError 2] 系统找不到指定的文件:、FileNotFoundError: [WinError 2] 系统找不到指定的文件、FileNotFoundError: [WinError 2] 系统找不到指定的文件。 解决方案的相关知识,请在本站搜索。

本文标签: