- Home /
ArgumentException: Name has invalid chars
Hi,
i'm using the following fucntion:
File.WriteAllBytes(Application.persistentDataPath + "/ingametext.txt",www.bytes);
And it gives me the following error which i find remarking because what is meant with the "Name" ???
ArgumentException: Name has invalid chars
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/FileStream.cs:253)
This is the code i use for extracting every package i need to download from a webserver:
TextAsset tuneInstall = Resources.Load("tune/install") as TextAsset;
string install = tuneInstall.text;
//split on newline
string[] arrPacks = install.Split("\n"[0]);
foreach (string pack in arrPacks)
{
if (pack.Contains("package"))
{
string[] splitPack = pack.Split(':');
if (!packs.Contains(splitPack[1]))
{
packs.Add(splitPack[1]);
}
}
}
And the file looks like this:
package:ingametext.txt
package:title.txt
Thanks!
Is that the actual code you're using? I've never heard of Application.persistentData
, but I have heard of similar properties, which makes me think you've retyped your code.
I didn't get
What Debug.Log(Application.persistentData + "/ingametext.txt") prints and for wich platform are you using? (ex: Android on unity editor).
I usually use
using (StreamWriter w = new StreamWriter(path)) {
w.WriteLine(Encrypt(Json.Encode(header)));
}
It seems the main problem comes from the wrong use of persistentData which is not a member of Application class, at least not the Unity one.
Yea know it was a typo i meant Application.persistentDataPath edited
Are you perhaps on a platform where /
is not the path separator? You might check if Path.Combine is more successful.
Without more information, this is a stab in the dark.
Answer by tanoshimi · Jun 02, 2014 at 06:31 PM
Do you mean Application.persistentDataPath?
Yea it was a typo i was using that. Now i've used another script for writing the file :
FileStream fs = new FileStream(sb.ToString(), File$$anonymous$$ode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(web.bytes);
sw.Close();
fs.Close();
And the output path is C:/Users/$$anonymous$$ilian/AppData/LocalLow/BeastGameWare/Exile/ingametext.txt
Generated by this code:
StringBuilder sb = new StringBuilder();
sb.Append(Application.persistentDataPath);
sb.Append("/");
sb.Append(pack);
And it still gives me the same error , i really dont get it.
Your answer
Follow this Question
Related Questions
C# How to read and cache text file data? 1 Answer
File exists not working applicationDataPath 1 Answer
WWW and File.Exists to check new file on server 1 Answer
Multiple Lists to CSV in C# 0 Answers
FileNotFound error without description 0 Answers