最好的做法是在您的文本编辑器中显示不可见",看看您是否能找到与其他空间不同的空间.EDIT 将您的代码段粘贴到我的文本编辑器中会在 FileUtils. 之后(在 . 和 mv).删除 FileUtils.mv 并重新键入它以删除您看不到的字符.When I run the below code in CodeRunner or from the command line I get the following error;Untitled.rb:25: Invalid char '\302' in expressionUntitled.rb:25: Invalid char '\255' in expressionLine 25 corresponds to the line with the FileUtils.mv method.if the_file.include? "Screen Shot" old_file = Shellwords.escape(homepath + "/Desktop/" + the_file) new_file = Shellwords.escape(screen_shot_folder + "/" + the_file) FileUtils.mv old_file, new_fileendInitially I thought there was something wrong with my input (either old_file or new_file) which is why I have wrapped them in Shellwords.escape I have also checked that the contents of old_file and new_file are correct.If I call puts old_file + " ++ " + new_file I get something like the following;/Users/tobyosbourn/Desktop/Screen\ Shot\ 2013-02-04\ at\ 10.49.14\ \(2\).png ++ /Users/tobyosbourn/Desktop/Screenshots/Screen\ Shot\ 2013-02-04\ at\ 10.49.14\ \(2\).pngWhich looks spot on but if I copy and paste those as strings into FileUtils.mv I get the same error message.I have read how FileUtils is meant to be used and couldn't see anything I am doing wrong, could anyone advise?If it helps my version of Ruby is 1.8.7 解决方案 You have an invisible non-ASCII character in your source code, likely added by copy-and-pasting code off a website somewhere.To be specific, you've got a rogue soft-hyphen in your code, encoded as UTF-8 (soft-hyphen = C2 AD in UTF-8, or \302\255 in octal escape notation).Best thing to do would be to "show invisibles" in your text editor and see if you can find a space that isn't like the others.EDIT Pasting your snippet into my text editor reveals a soft-hyphen right after FileUtils. (between . and mv). Delete FileUtils.mv and retype it to get rid of the character if you can't see it. 这篇关于FileUtils.mv 抛出 Invalid char \302 和 \255 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 21:10