title: Closed: How to read a temporary file as bytes in Flutter?
body: <p>So basically I am using <code>flutter_sound</code> to record an audio file:</p>
  <pre><code>class AudioRecorder {
    FlutterSoundRecorder? _audioRecorder;
    String tempFilePath = &quot;audio_recording.mp4&quot;;
  
    Future&lt;void&gt; init() async {
      _audioRecorder = FlutterSoundRecorder();
      await _audioRecorder!.openRecorder();
    }
  
    Future&lt;void&gt; dispose() async {
      await _audioRecorder!.openRecorder();
      _audioRecorder = null;
    }
  
    Future&lt;void&gt; startRecording() async {
      await _audioRecorder!.startRecorder(toFile: tempFilePath);
    }
  
    Future&lt;File&gt; stopRecording() async {
      await _audioRecorder!.stopRecorder();
      return File(tempFilePath);
    }
  }
  </code></pre>
  <p>This class works as intended and a file is returned by <code>stopRecording();</code>.</p>
  <p><strong>The issue:</strong></p>
  <p>When I try to <code>audioFile.readAsBytesSync();</code>, this error occurs:</p>
  <blockquote>
  <p>Unhandled Exception: FileSystemException: Cannot open file, path = 'audio_recording.mp4' (OS Error: No such file or directory, errno = 2)</p>
  </blockquote>
  <p><strong>What I think is wrong:</strong></p>
  <p>When I do <code>print(audioFile.path);</code>, the output is <code>&quot;audio_recording.mp4&quot;</code> however when I stop recording the audio, <code>flutter_sound</code> also prints a path to the file but its different:</p>
  <blockquote>
  <p>&quot;/Users/.../Library/Developer/CoreSimulator/Devices/.../data/Containers/Data/Application/.../tmp/audio_recording.mp4&quot;</p>
  </blockquote>
  <p>When I <code>readAsBytesSync</code> to a <code>File</code> object that has this path, there is no exception. So I somehow have to get this path but I cannot figure out how. I have tried using <code>path_provider and getTemporaryDirectory</code> but its to no avail since the path from getTemporaryDirectory is different to the one printed by flutter_sound.</p>
  <p>How could I fix this?</p>
  <p>Thank you!</p>