• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read .txt files in android from computer.

 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey
My Question is how to read txt files in android from computer in by that i mean like this



And It shows "no such file or directory"

Even if i check .exists on a file it prints false

And the directory file is EXISTS!

Thanks in advance.


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I understand. Is that code that you are running on Android? Because Android runs Linux and there is no C:\ drive, "C:\\Users\\user\\workspace\\project\\Test.txt" is an impossible path on Android.

So what exactly are you trying to do?
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes this code I'm running on android , and what I'm trying to read is from the computer (Windows).
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how does the file get from Windows to Android?
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that on android project you can do the same in Regular Project (Without Android) and by i mean is that in regular project you can Write and read to where ever you liked to write , in your computer (and also read from there)
So i guess it dosent?
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are aware that you have Windows file paths in the code above?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Shef wrote:I thought that on android project you can do the same in Regular Project (Without Android) and by i mean is that in regular project you can Write and read to where ever you liked to write , in your computer (and also read from there)
So i guess it dosent?

No, it doesn't. The Android device is a virtual machine, for all intents and purposes a different computer. So if you save a file to computer A, then switch to computer B, you wouldn't expect to find the same file. Unless you do something to transport it from A to B. Same thing needs to happen here.
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me explain again

I have a Java project that writes to the windows and this case it is my documents folder , and to "Test.txt" so i tried when i wrote to the documents from my java project (regular project , not android) and read from android and prints it. i even tried to set the regular project into the android project build path but i just cannot get the right path to the txt file
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does this Android code run - in an emulator on the computer? But even then I don't think you can access the host computer's file system like that.

Let's take a step back: What are you trying to achieve by that? Once the code runs on an actual Android device, there will certainly be no Windows drive, C: or otherwise. But even if it worked in the emulator, what point is there in accessing a drive from within your Android code when that has no chance of working on an actual device?
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to achieve when ever something happens on the regular project it writes to the windows txt file and then when i turn on the android or press a button it gets (reads) the txt files from windows and prints it and thats what i want to achieve. and no it is on real device not emulator.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Shef wrote:Let me explain again

I have a Java project that writes to the windows and this case it is my documents folder , and to "Test.txt" so i tried when i wrote to the documents from my java project (regular project , not android) and read from android and prints it.

A Java project runs in the Java runtime environment, on the same computer. Since it is on the same computer it has access to the computer's file system. Your Android emulator is not on the same computer, it is on a virtual machine, and has just about the same access to your computer's file system as I do. And since it isn't Windows, even if it had access to the computer's file system you would have to use a linux-type path to address is (like /media/host_computer/c/Users/user/workspace/project/Test.txt <- which you can't do because you don't actually have access, that is just an example if you figured out how to mount your computer's C:\ drive to the Android's file system <- which you shouldn't do because when you run the application from a real device you wouldn't have access to it anyway!).

So I think what you need to do is define what that file is supposed to be, and how you expect it to be used/retrieved by the user on a REAL device that has no relationship to the Windows development computer. Then maybe we can help you figure out how to set the file up in the right spot.
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to write a string when something happens in the regular project and write it to windows documents files and read it on the android project it will work.
i even tried to return the string by doing this "public static getString(){ return string}"

DID NOT WORK!

So i figured out if i could write to the windows documents files a string and read from android i could achieve and get the string from what i wrote on the regular project...
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again: What is the point of an "Android project" doing something that is not possible on an actual device?
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what should i do , can you give me a code example?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're missing the point: there is no code to do this - it does not make sense on a very fundamental level:
What is the point of an "Android project" doing something that is not possible on an actual device?

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Shef wrote:So what should i do , can you give me a code example?

You have an Android application, and you have a Java application. What is the relationship between them? What does the Java application do? What does the Android application do? When I download the Android app from the App Store, how do I use it?

What is this String that the Java app creates? Why does it need to be created in the Java application? Can the Android application create the String?

We can't give you an example of how to do something if you don't tell us what the 'something' it is you want to do.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this about data exchange, or is it about debugging?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic