You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行音频指纹对比Java代码时出现“找不到文件或目录”错误,如何解决?

Fixing the "File Not Found" Error in Your Audio Fingerprinting Java Code

Hey there, let's work through that frustrating "file or directory not found" error you're hitting with your audio fingerprinting code! I've gone through your code and the setup, so here are the key fixes and checks to get things running smoothly:

1. Verify Your File Path Structure

First up, let's make sure your files are where your code expects them to be:

  • If this is a standard Java project, your res/raw folder needs to live in the root directory of your project (at the same level as your src folder), not nested inside src. If it's in the wrong place, the JVM won't be able to locate your WAV files.
  • To rule out path confusion entirely, test with an absolute file path first. For example:
    String songA = "/Users/your-username/your-project-folder/res/raw/canon_d_major.wav";
    
    If this works, your relative path was the issue—adjust your folder structure or path accordingly.

2. Double-Check Filename Spelling & Case

Operating systems like Linux and macOS are case-sensitive, so make sure:

  • The filenames match exactly what's in your code: canon_d_major.wav and cock_a.1.wav (pay close attention to the .1 in the second filename—easy to miss a typo here!).
  • Even on Windows (which is case-insensitive), typos in the filename (like canon_d_major.WAV instead of .wav) can still cause issues.

3. Confirm the Files Actually Exist

It sounds obvious, but it's easy to overlook:

  • Navigate to your res/raw folder manually and check that all three WAV files are present. Sometimes files get deleted accidentally, or fail to copy over correctly when setting up the project.

4. Fix the Variable Name Bug in Your Code

While this isn't causing the file error, you've got a small typo that will break your code once the file issue is fixed: you're using similarity to call methods, but your variables are named similarity1 and similarity2. Here's the corrected code:

public static void main(String[] args) {
    String songA = "res/raw/canon_d_major.wav";
    String songB = "res/raw/canon_d_major.wav";
    Wave waveA = new Wave(songA);
    Wave waveB = new Wave(songB);
    
    String recordedClip = "res/raw/cock_a.1.wav";
    Wave waveRec = new Wave(recordedClip);
    
    FingerprintSimilarity similarity1, similarity2;
    similarity1 = waveA.getFingerprintSimilarity(waveRec);
    System.out.println("clip is found at " + similarity1.getsetMostSimilarTimePosition() + "s in " + songA + " with similarity " + similarity1.getSimilarity());
    
    similarity2 = waveB.getFingerprintSimilarity(waveRec);
    System.out.println("clip is found at " + similarity2.getsetMostSimilarTimePosition() + "s in " + songB + " with similarity " + similarity2.getSimilarity());
}

Start with the file path checks first—those are the most common culprits here. Once you get past the file error, the variable name fix will ensure your output works as expected!

内容的提问来源于stack exchange,提问作者Yosra Bader

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:46:29