C# Programındaki Hata Nedir?

Cengizhanjj

Femtopat
Katılım
8 Aralık 2022
Mesajlar
52
Daha fazla  
Cinsiyet
Erkek
Selam 2-3 saattir üzerinde uğraştığım koddan hata alıyorum. Kod:

Using System;
Using System. IO;

Namespace sifreuygulamasi.
{
Class program.
{
Static Void main(string[] args)
{ while(true)
{
Console.Write("İşleminizi Girin \n Kayıt için 1 yazin \n giriş için 2 yazin ");
string islem=Console.ReadLine();
if(islem=="2")
{
Console.Write("\nAdinizi Girin: ");
string isim2 = Console.ReadLine();
Console.Write("Sifrenizi Girin: ");
string sifre2 = Console.ReadLine();
String isim = "";
String sifre = "1";
if (isim == isim2 && sifre == sifre2)
{
Console.WriteLine("Giriş Başarılı Hoşgeldin {0}", isim);
}
else.
{
Console.Write("Birisi Yanlış ama hangisi söylemem");
}
}
if(islem=="1");
{

FileStream fs = new FileStream("D://storage/emulated/0/Download deneme.txt",FileMode.Append,FileAccess.Write,FileShare.Write);
StreamWriter sw = new StreamWriter(fs);
Console.Write("Adınız : ");
sw.WriteLine(Console.ReadLine());
sw.Close();
Console.WriteLine("Kayıt Eklendi.");
Console.ReadKey();
}
}

}
}
}
 
C#:
Using System;
Using System. IO;

Namespace sifreuygulamasi.
{
Class program.
{
Static Void main(string[] args)
{ while(true)
{
Console.Write("İşleminizi Girin \n Kayıt için 1 yazin \n giriş için 2 yazin ");
string islem=Console.ReadLine();
if(islem=="2")
{
Console.Write("\nAdinizi Girin: ");
string isim2 = Console.ReadLine();
Console.Write("Sifrenizi Girin: ");
string sifre2 = Console.ReadLine();
String isim = "";
String sifre = "1";
if (isim == isim2 && sifre == sifre2)
{
Console.WriteLine("Giriş Başarılı Hoşgeldin {0}", isim);
}
else.
{
Console.Write("Birisi Yanlış ama hangisi söylemem");
}
}
if(islem=="1");
{

FileStream fs = new FileStream("D://storage/emulated/0/Download deneme.txt",FileMode.Append,FileAccess.Write,FileShare.Write);
StreamWriter sw = new StreamWriter(fs);
Console.Write("Adınız : ");
sw.WriteLine(Console.ReadLine());
sw.Close();
Console.WriteLine("Kayıt Eklendi.");
Console.ReadKey();
}
}

}
}
}

Kodu bu şekilde atarsanız ve hatayı da atarsanız iyi olur.
 
C#:
using System;
using System.IO;

namespace sifreuygulamasi
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Write("İşleminizi Girin \n Kayıt için 1 yazin \n giriş için 2 yazin ");
string islem = Console.ReadLine();

            if (islem == "2")
            {
                Console.Write("\nAdinizi Girin: ");
                string isim2 = Console.ReadLine();
                Console.Write("Sifrenizi Girin: ");
                string sifre2 = Console.ReadLine();

                String isim = "";
                String sifre = "1";

                if (isim == isim2 && sifre == sifre2)
                {
                    Console.WriteLine("Giriş Başarılı Hoşgeldin {0}", isim);
                }
                else
                {
                    Console.Write("Birisi Yanlış ama hangisi söylemem");
                }
            }

            if (islem == "1")
            {
                FileStream fs = new FileStream("D://storage/emulated/0/Download deneme.txt", FileMode.Append, FileAccess.Write, FileShare.Write);
                StreamWriter sw = new StreamWriter(fs);
                Console.Write("Adınız : ");
                sw.WriteLine(Console.ReadLine());
                sw.Close();
                Console.WriteLine("Kayıt Eklendi.");
                Console.ReadKey();
            }
        }
    }
}
}
 
Tabiki

System.IO.DirectoryNotFoundException: Could not find a part of the path "/storage/emulated/0/Android/data/com.radinc.csharpshell/files/CSharpShell/examples/HelloWorld/D:/storage/emulated/0/Download deneme.txt".
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0017d] in <97c6c40360454c158c014ee803ea6785>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <97c6c40360454c158c014ee803ea6785>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at sifreuygulamasi.Program.Main (System.String[] args) [0x0008d] in <d6768dd1c5624ad68ef3700189ff20cc>:0
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <97c6c40360454c158c014ee803ea6785>:0
 
Android dosya erişimine vs izin vermiyor olabilir. Kodu bilgisayarda yazarsanız hata vermeyecektir tahminimce.
 

Technopat Haberler

Yeni konular

Geri
Yukarı