Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux shows that the file cannot be found. How to solve the exception?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux shows that the file can not be found abnormal how to solve? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Scene:

The project accesses normally under windows, but the linux throws an exception and the file cannot be found.

Analysis:

If the project file accessed is like this: abc/bcd/aa.jpg, and the path to the access file in the system is: abc/Bcd/aa.jpg, the difference between the two is that the secondary directory bcd is written as Bcd.

If you develop under windows, you can't find the error. The windows file name is case-insensitive, so you can still access the file according to abc/Bcd/aa.jpg, but the linux file directory is case-sensitive, so you can't find the file.

Solution:

In normal programming, you must write strictly.

It should also be noted that the linux directory separator is /, and under windows is\, so sometimes the file path stored in windows to the database will not be applicable to linux. It needs to be processed in the system. After the path is removed from the database, it needs to be processed as follows:

/ * modify the path, replace\\ or / with File.separator * @ param path path to be modified * @ return modified path * / public static String path (String path) {String p = StringUtils.replace (path, "\", "/"); p = StringUtils.join (StringUtils.split (p, "/"), "/") If (! StringUtils.startsWithAny (p, "/") & & StringUtils.startsWithAny (path, "\\", "/")) {p + = "/";} if (! StringUtils.endsWithAny (p, "/") & & StringUtils.endsWithAny (path, "\", "/")) {p = p + "/" } if (path! = null & & path.startsWith ("/")) {p = "/" + p; / / path under linux} return p } this is the answer to the problem of how to solve the problem when the linux display cannot find a file exception. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report